Commit 6274eb5d authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

refactoring

parent cd994e0f
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -41,14 +41,10 @@ class HomeController extends AbstractController
        return $this->json($result);
    }

    #[Route('/', name: 'home', methods: ['POST'])]
    #[Route('/func3', name: 'home', methods: ['POST'])]
    public function home(Request $request): Response
    {
        $array = $request->get('arr');
        $errors = ArrayValidation::validate($array);
        if (count($errors) > 0) {
            return new Response((string)$errors);
        }
        $result = $this->functions->uniqElements($array);
        return $this->json($result);
    }
+0 −17
Original line number Diff line number Diff line
@@ -17,21 +17,4 @@ class ArrayValidation
        $ages = array_column($array, 'age');
        return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages));
    }

    public static function validate(array $array): ConstraintViolationListInterface
    {
        $validator = Validation::createValidator();
        $constraints = new Assert\Optional([
            new Assert\Collection([
                new Assert\Optional([
                    new Assert\Type('array'),
                    new Assert\Collection([
                        new Assert\Type('string'),
                        new Assert\Type('string'),
                    ])
                ])
            ])
        ]);
        return $validator->validate($array, $constraints);
    }
}
 No newline at end of file