Failed Conditions
Pull Request — release/1.0.0 (#4)
by Yo
02:07 queued 27s
created

JsonRpcParamsValidator::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 12
1
<?php
2
namespace Yoanm\JsonRpcParamsSymfonyValidator\Infra;
3
4
use Symfony\Component\Validator\Validator\ValidatorInterface;
5
use Yoanm\JsonRpcParamsSymfonyValidator\Model\MethodWithValidatedParams;
0 ignored issues
show
Bug introduced by
The type Yoanm\JsonRpcParamsSymfo...thodWithValidatedParams was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Yoanm\JsonRpcServer\Domain\Event\Action\ValidateParamsEvent;
7
8
/**
9
 * Class JsonRpcParamsValidator
10
 */
11
class JsonRpcParamsValidator
12
{
13
    /** @var ValidatorInterface */
14
    private $validator;
15
16
    /**
17
     * @param ValidatorInterface $validator
18
     */
19
    public function __construct(ValidatorInterface $validator)
20
    {
21
        $this->validator = $validator;
22
    }
23
24
    /**
25
     * @param ValidateParamsEvent $event
26
     */
27
    public function validate(ValidateParamsEvent $event)
28
    {
29
        $method = $event->getMethod();
30
        if (!$method instanceof MethodWithValidatedParams) {
31
            return;
32
        }
33
        foreach ($this->validator->validate($event->getParamList(), $method->getParamsConstraint()) as $violation) {
0 ignored issues
show
Bug introduced by
The method getParamsConstraint() does not exist on Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        foreach ($this->validator->validate($event->getParamList(), $method->/** @scrutinizer ignore-call */ getParamsConstraint()) as $violation) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            $event->addViolation([
35
                'path' => $violation->getPropertyPath(),
36
                'message' => $violation->getMessage(),
37
                'code' => $violation->getCode(),
38
            ]);
39
        }
40
    }
41
}
42