1 | <?php |
||
25 | class ValidationService implements ValidationServiceInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var ValidatorInterface |
||
29 | */ |
||
30 | protected $validator; |
||
31 | |||
32 | /** |
||
33 | * ValidationService constructor. |
||
34 | * @param ValidatorInterface $validator |
||
35 | */ |
||
36 | 6 | public function __construct(ValidatorInterface $validator) |
|
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | 1 | public function validate($data, array $groups = null) |
|
45 | { |
||
46 | 1 | $errors = []; |
|
47 | |||
48 | 1 | $violations = $this->validator->validate($data, null, $groups); |
|
|
|||
49 | 1 | foreach ($violations as $violation) { |
|
50 | /* @var $violation \Symfony\Component\Validator\ConstraintViolationInterface */ |
||
51 | |||
52 | if ($data instanceof EncodingParametersInterface) { |
||
53 | $source = ['parameter' => $violation->getPropertyPath()]; |
||
54 | } else { |
||
55 | $source = ['pointer' => $this->prepareSourcePath($violation->getPropertyPath())]; |
||
56 | } |
||
57 | |||
58 | $errors[] = new Error( |
||
59 | rand(), |
||
60 | null, |
||
61 | 422, |
||
62 | $violation->getCode(), |
||
63 | $violation->getMessage(), |
||
64 | null, |
||
65 | $source |
||
66 | ); |
||
67 | 1 | } |
|
68 | |||
69 | 1 | return $errors; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param string $path |
||
74 | * @return string |
||
75 | */ |
||
76 | private function prepareSourcePath($path) |
||
80 | } |
||
81 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.