Skip to content

Commit

Permalink
Make CakeValidationValidationConverter non static
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Sep 4, 2021
1 parent 8cc3918 commit 1279f52
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 37 additions & 0 deletions src/Converter/ValitronValidationValidationConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Selective\Validation\Converter;

use Selective\Validation\ValidationResult;

/**
* Valitron validation error collector.
*/
final class ValitronValidationValidationConverter implements ValidationConverterInterface
{
/**
* Create validation result from array with errors.
*
* @param array $errors The errors
*
* @return ValidationResult The result
*/
public function createValidationResult($errors): ValidationResult
{
$result = new ValidationResult();

$fields = [];

foreach ($errors as $field => $message) {
if (isset($fields[$field])) {
continue;
}

$result->addError($field, $message);

$fields[$field] = 1;
}

return $result;
}
}
4 changes: 2 additions & 2 deletions src/Factory/CakeValidationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -30,6 +30,6 @@ public function createValidator(): Validator
*/
public function createValidationResult(array $errors): ValidationResult
{
return (new CakeValidationValidationConverter())->createValidationResult($errors);
return (new CakeValidationConverter())->createValidationResult($errors);
}
}
6 changes: 3 additions & 3 deletions tests/Converter/CakeValidationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
],
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testCreateResultFromErrorsSimple()
*/
public function testCreateResultFromErrorsNestedArray()
{
$result = (new CakeValidationValidationConverter())->createValidationResult([
$result = (new CakeValidationConverter())->createValidationResult([
'bills' => [
0 => [
'billing_number' => [
Expand Down

0 comments on commit 1279f52

Please sign in to comment.