diff --git a/src/Converter/CakeValidationValidationConverter.php b/src/Converter/CakeValidationConverter.php similarity index 95% rename from src/Converter/CakeValidationValidationConverter.php rename to src/Converter/CakeValidationConverter.php index 2f3ada8..9c2b0da 100644 --- a/src/Converter/CakeValidationValidationConverter.php +++ b/src/Converter/CakeValidationConverter.php @@ -7,7 +7,7 @@ /** * CakePHP validation error convert. */ -final class CakeValidationValidationConverter implements ValidationConverterInterface +final class CakeValidationConverter implements ValidationConverterInterface { /** * Create validation result from array with errors. diff --git a/src/Converter/ValitronValidationValidationConverter.php b/src/Converter/ValitronValidationValidationConverter.php new file mode 100644 index 0000000..6003644 --- /dev/null +++ b/src/Converter/ValitronValidationValidationConverter.php @@ -0,0 +1,37 @@ + $message) { + if (isset($fields[$field])) { + continue; + } + + $result->addError($field, $message); + + $fields[$field] = 1; + } + + return $result; + } +} diff --git a/src/Factory/CakeValidationFactory.php b/src/Factory/CakeValidationFactory.php index ba0aba6..b9c208a 100644 --- a/src/Factory/CakeValidationFactory.php +++ b/src/Factory/CakeValidationFactory.php @@ -3,7 +3,7 @@ namespace Selective\Validation\Factory; use Cake\Validation\Validator; -use Selective\Validation\Converter\CakeValidationValidationConverter; +use Selective\Validation\Converter\CakeValidationConverter; use Selective\Validation\ValidationResult; /** @@ -30,6 +30,6 @@ public function createValidator(): Validator */ public function createValidationResult(array $errors): ValidationResult { - return (new CakeValidationValidationConverter())->createValidationResult($errors); + return (new CakeValidationConverter())->createValidationResult($errors); } } diff --git a/tests/Converter/CakeValidationFactoryTest.php b/tests/Converter/CakeValidationFactoryTest.php index 9bfd725..9608e00 100644 --- a/tests/Converter/CakeValidationFactoryTest.php +++ b/tests/Converter/CakeValidationFactoryTest.php @@ -3,7 +3,7 @@ namespace Selective\Validation\Test\Converter; use PHPUnit\Framework\TestCase; -use Selective\Validation\Converter\CakeValidationValidationConverter; +use Selective\Validation\Converter\CakeValidationConverter; use Selective\Validation\Transformer\ErrorDetailsResultTransformer; use Selective\Validation\ValidationResult; @@ -31,7 +31,7 @@ private function getValidationResultAsArray(ValidationResult $validationResult): */ public function testCreateResultFromErrorsSimple() { - $result = (new CakeValidationValidationConverter())->createValidationResult([ + $result = (new CakeValidationConverter())->createValidationResult([ 'first_name' => [ '_empty' => 'This field cannot be left empty', ], @@ -104,7 +104,7 @@ public function testCreateResultFromErrorsSimple() */ public function testCreateResultFromErrorsNestedArray() { - $result = (new CakeValidationValidationConverter())->createValidationResult([ + $result = (new CakeValidationConverter())->createValidationResult([ 'bills' => [ 0 => [ 'billing_number' => [