Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( b608ac...5a9349 )
by Jérémiah
43:50 queued 29:55
created

ExpressionValidator::validate()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4.0032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 25
ccs 16
cts 17
cp 0.9412
rs 9.7333
c 1
b 0
f 0
cc 4
nc 5
nop 2
crap 4.0032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Validator\Constraints;
6
7
use Overblog\GraphQLBundle\Validator\ValidationNode;
8
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
9
use Symfony\Component\HttpKernel\Kernel;
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Constraints\Expression;
12
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
13
14
class ExpressionValidator extends \Symfony\Component\Validator\Constraints\ExpressionValidator
15
{
16
    private $expressionLanguage;
17
18 9
    public function __construct(ExpressionLanguage $expressionLanguage)
19
    {
20 9
        $this->expressionLanguage = $expressionLanguage;
21 9
        if (Kernel::VERSION_ID >= 40400) {
22 9
            parent::__construct($expressionLanguage);
23
        } else {
24
            parent::__construct(null, $expressionLanguage);
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Component\Valida...alidator::__construct() has too many arguments starting with $expressionLanguage. ( Ignorable by Annotation )

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

24
            parent::/** @scrutinizer ignore-call */ 
25
                    __construct(null, $expressionLanguage);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
        }
26 9
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 9
    public function validate($value, Constraint $constraint): void
32
    {
33 9
        if (!$constraint instanceof Expression) {
34
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression');
35
        }
36
37 9
        $variables = $constraint->values;
38 9
        $variables['value'] = $value;
39
40 9
        $object = $this->context->getObject();
41
42 9
        $variables['this'] = $object;
43
44 9
        if ($object instanceof ValidationNode) {
45 9
            $variables['parentValue'] = $object->getResolverArg('value');
46 9
            $variables['context'] = $object->getResolverArg('context');
47 9
            $variables['args'] = $object->getResolverArg('args');
48 9
            $variables['info'] = $object->getResolverArg('info');
49
        }
50
51 9
        if (!$this->expressionLanguage->evaluate($constraint->expression, $variables)) {
52 4
            $this->context->buildViolation($constraint->message)
53 4
                ->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
54 4
                ->setCode(Expression::EXPRESSION_FAILED_ERROR)
55 4
                ->addViolation();
56
        }
57 9
    }
58
}
59