From 7c17007d849811bc7a9c235f4fe8864741b00bbb Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 25 Nov 2023 08:25:24 +0000 Subject: [PATCH] refactor(validator): remove duplicate constraints e.g. if a constraint is a choice of strings, that implies the value must be a string so there's no need for an additional type constraint. --- CHANGELOG.md | 6 ++++++ src/DataTransferObject/Config.php | 25 ------------------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c692ce0..7099d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2023-11-24 + +### Changed + +* Simplified constraints on properties within the `Config` DTO class. + ## 2023-11-23 ### Added diff --git a/src/DataTransferObject/Config.php b/src/DataTransferObject/Config.php index 6b05922..b25973c 100644 --- a/src/DataTransferObject/Config.php +++ b/src/DataTransferObject/Config.php @@ -8,8 +8,6 @@ use Symfony\Component\Validator\Constraints as Assert; final class Config { - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -23,7 +21,6 @@ final class Config 'type' => new Assert\Required([ new Assert\Choice(choices: ['mariadb', 'mysql']), - new Assert\Type('string'), ]), 'version' => new Assert\Required([ @@ -33,8 +30,6 @@ final class Config )] public array $database; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -49,8 +44,6 @@ final class Config )] public array $dockerCompose; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -110,16 +103,12 @@ final class Config )] public array $dockerfile; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: ['docroot' => new Assert\Choice([null, 'web', 'docroot'])], )] public array $drupal; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -139,8 +128,6 @@ final class Config )] public array $experimental; - #[Assert\Type('array')] - #[Assert\Valid()] #[Assert\Collection([ 'ignore' => new Assert\Optional([ new Assert\All([ @@ -150,8 +137,6 @@ final class Config ])] public array $git; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -170,7 +155,6 @@ final class Config )] public array $flake; - #[Assert\Type('string')] #[Assert\Choice(choices: ['javascript', 'php', 'typescript'])] public string $language; @@ -178,8 +162,6 @@ final class Config #[Assert\Type('string')] public string $name; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -190,8 +172,6 @@ final class Config )] public array $node; - #[Assert\Type('array')] - #[Assert\Valid] #[Assert\Collection( allowExtraFields: false, fields: [ @@ -259,16 +239,11 @@ final class Config #[Assert\Type('string')] public string $projectRoot; - #[Assert\NotBlank] - #[Assert\Type('string')] #[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'symfony', 'terraform'])] public string $type; - #[Assert\Type('array')] - #[Assert\Valid()] #[Assert\Collection([ 'type' => new Assert\Required([ - new Assert\Type('string'), new Assert\Choice(choices: ['nginx', 'caddy']), ]), ])]