Skip to content
Snippets Groups Projects
Commit 6274eb5d authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

refactoring

parent cd994e0f
No related branches found
No related tags found
1 merge request!3Ptps controller 3
......@@ -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);
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment