Skip to content

Commit

Permalink
Rename DTO class and variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
opdavies committed Dec 15, 2023
1 parent 537a715 commit de990f3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions src/Action/CreateListOfFilesToGenerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function handle(array $configurationDataAndDto, \Closure $next)
* @var Config $configurationDataDto,
* @var array<string,mixed> $configurationData
*/
[$configurationData, $configurationDataDTO] = $configurationDataAndDto;
[$configurationData, $configDto] = $configurationDataAndDto;

/** @var Collection<int, TemplateFile> */
$filesToGenerate = collect();

switch (strtolower($configurationDataDTO->type)) {
switch (strtolower($configDto->type)) {
case (strtolower(ProjectType::Astro->name)):
$filesToGenerate = collect([
new TemplateFile(data: 'astro/.envrc', name: '.envrc'),
Expand All @@ -41,14 +41,14 @@ public function handle(array $configurationDataAndDto, \Closure $next)
new TemplateFile(data: 'fractal/run', name: 'run'),
]);

if ($configurationDataDTO->isDocker) {
if ($configDto->isDocker) {
$filesToGenerate->push(new TemplateFile(data: 'fractal/.env.example', name: '.env.example'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/.dockerignore', name: '.dockerignore'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/.hadolint.yaml', name: '.hadolint.yaml'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/.yarnrc', name: '.yarnrc'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/Dockerfile', name: 'Dockerfile'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/docker-compose.yaml', name: 'docker-compose.yaml'));
} elseif ($configurationDataDTO->isFlake) {
} elseif ($configDto->isFlake) {
$filesToGenerate->push(new TemplateFile(data: 'fractal/.envrc', name: '.envrc'));
$filesToGenerate->push(new TemplateFile(data: 'fractal/flake.nix', name: 'flake.nix'));
}
Expand Down Expand Up @@ -82,15 +82,15 @@ public function handle(array $configurationDataAndDto, \Closure $next)
));
}

if ($configurationDataDTO->php['phpcs'] !== false) {
if (!isset($configDto->php['phpcs']) || $configDto->php['phpcs'] !== false) {
$filesToGenerate->push(new TemplateFile(data: 'drupal/phpcs.xml.dist', name: 'phpcs.xml.dist'));
}

if ($configurationDataDTO->php['phpstan'] !== false) {
if (!isset($configDto->php['phpstan']) || $configDto->php['phpstan'] !== false) {
$filesToGenerate->push(new TemplateFile(data: 'drupal/phpstan.neon.dist', name: 'phpstan.neon.dist'));
}

if ($configurationDataDTO->php['phpunit'] !== false) {
if (!isset($configDto->php['phpunit']) || $configDto->php['phpunit'] !== false) {
$filesToGenerate->push(new TemplateFile(data: 'drupal/phpunit.xml.dist', name: 'phpunit.xml.dist'));
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public function handle(array $configurationDataAndDto, \Closure $next)
);
}

return $next([$configurationData, $configurationDataDTO, $filesToGenerate]);
return $next([$configurationData, $configDto, $filesToGenerate]);
}

private static function isCaddy(?string $webServer): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Action/GenerateConfigurationFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Action;

use App\DataTransferObject\Config;
use App\DataTransferObject\ConfigDto;
use App\DataTransferObject\TemplateFile;
use Illuminate\Support\Collection;
use Symfony\Component\Filesystem\Filesystem;
Expand All @@ -23,7 +23,7 @@ public function handle(array $filesToGenerateAndConfigurationData, \Closure $nex
{
/**
* @var Collection<int,TemplateFile> $filesToGenerate
* @var Config $configurationDataDto,
* @var ConfigDto $configurationDataDto,
* @var array<string,mixed> $configurationData
*/
[$configurationData, $configurationDataDto, $filesToGenerate] = $filesToGenerateAndConfigurationData;
Expand Down
4 changes: 2 additions & 2 deletions src/Action/ValidateConfigurationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Action;

use App\DataTransferObject\Config;
use App\DataTransferObject\ConfigDto;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand All @@ -18,7 +18,7 @@ public function handle(array $configurationData, \Closure $next) {
$normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter());
$serializer = new Serializer([$normalizer], [new JsonEncoder()]);

$configurationDataDto = $serializer->deserialize(json_encode($configurationData), Config::class, 'json');
$configurationDataDto = $serializer->deserialize(json_encode($configurationData), ConfigDto::class, 'json');

$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$violations = $validator->validate($configurationDataDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\Validator\Constraints as Assert;

final class Config
final class ConfigDto
{
#[Assert\Collection(
allowExtraFields: false,
Expand Down
46 changes: 23 additions & 23 deletions tests/Kernel/Validator/ConfigurationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Tests;

use App\DataTransferObject\Config;
use App\DataTransferObject\ConfigDto;
use App\Enum\ProjectType;
use App\Enum\WebServer;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
Expand All @@ -12,13 +12,13 @@

class ConfigurationValidatorTest extends KernelTestCase
{
private Config $configurationDataDTO;
private ConfigDto $configurationDataDto;

private ValidatorInterface $validator;

public function setUp(): void
{
$this->configurationDataDTO = self::createConfigurationDTO();
$this->configurationDataDto = self::createConfigurationDto();

$this->validator = Validation::createValidatorBuilder()
->enableAttributeMapping()
Expand All @@ -34,13 +34,13 @@ public function testThatExtraDatabasesCanBeSpecified(
?string $expectedMessage,
): void
{
$this->configurationDataDTO->database = [
$this->configurationDataDto->database = [
'extra_databases' => $extraDatabases,
'type' => 'mariadb',
'version' => 10,
];

$violations = $this->validator->validate($this->configurationDataDTO);
$violations = $this->validator->validate($this->configurationDataDto);

self::assertCount(
expectedCount: $expectedViolationCount,
Expand Down Expand Up @@ -72,10 +72,10 @@ public function testTheProjectNameShouldBeAString(
self::expectException(NotNormalizableValueException::class);
}

$configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->name = $projectName;
$configurationDataDto = self::createConfigurationDto();
$configurationDataDto->name = $projectName;

$violations = $this->validator->validate($configurationDataDTO);
$violations = $this->validator->validate($configurationDataDto);

self::assertCount(
expectedCount: $expectedViolationCount,
Expand All @@ -98,10 +98,10 @@ public function testTheProjectLanguageShouldBeASupportedLanguage(
int $expectedViolationCount,
?string $expectedMessage,
): void {
$configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->language = $language;
$configurationDataDto = self::createConfigurationDto();
$configurationDataDto->language = $language;

$violations = $this->validator->validate($configurationDataDTO);
$violations = $this->validator->validate($configurationDataDto);

self::assertCount(
expectedCount: $expectedViolationCount,
Expand Down Expand Up @@ -129,10 +129,10 @@ public function testTheProjectTypeShouldBeASupportedType(
int $expectedViolationCount,
?string $expectedMessage,
): void {
$configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->type = $projectType;
$configurationDataDto = self::createConfigurationDto();
$configurationDataDto->type = $projectType;

$violations = $this->validator->validate($configurationDataDTO);
$violations = $this->validator->validate($configurationDataDto);

self::assertCount(
expectedCount: $expectedViolationCount,
Expand Down Expand Up @@ -160,10 +160,10 @@ public function testTheWebServerTypeIsValid(
int $expectedViolationCount,
?string $expectedMessage,
): void {
$configurationDataDTO = self::createConfigurationDTO();
$configurationDataDTO->web['type'] = $webServer;
$configurationDataDto = self::createConfigurationDto();
$configurationDataDto->web['type'] = $webServer;

$violations = $this->validator->validate($configurationDataDTO);
$violations = $this->validator->validate($configurationDataDto);

self::assertCount(
expectedCount: $expectedViolationCount,
Expand Down Expand Up @@ -233,13 +233,13 @@ public static function validWebServerTypes(): \Generator
];
}

private static function createConfigurationDTO(): Config
private static function createConfigurationDto(): ConfigDto
{
$configurationDataDTO = new Config();
$configurationDataDTO->language = 'php';
$configurationDataDTO->name = 'test';
$configurationDataDTO->type = 'drupal';
$configurationDataDto = new ConfigDto();
$configurationDataDto->language = 'php';
$configurationDataDto->name = 'test';
$configurationDataDto->type = 'drupal';

return $configurationDataDTO;
return $configurationDataDto;
}
}

0 comments on commit de990f3

Please sign in to comment.