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
Pull Request — master (#698)
by Jérémiah
06:04
created

ExpressionValidator::validate()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4.0027

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 26
ccs 17
cts 18
cp 0.9444
rs 9.7
cc 4
nc 5
nop 2
crap 4.0027
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Validator\Constraints;
6
7
use Overblog\GraphQLBundle\Definition\GlobalVariables;
8
use Overblog\GraphQLBundle\Validator\ValidationNode;
9
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
10
use Symfony\Component\HttpKernel\Kernel;
11
use Symfony\Component\Validator\Constraint;
12
use Symfony\Component\Validator\Constraints\Expression;
13
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
14
15
class ExpressionValidator extends \Symfony\Component\Validator\Constraints\ExpressionValidator
16
{
17
    private $expressionLanguage;
18
19
    private $globalVariables;
20
21 9
    public function __construct(ExpressionLanguage $expressionLanguage, GlobalVariables $globalVariables)
22
    {
23 9
        $this->expressionLanguage = $expressionLanguage;
24 9
        $this->globalVariables = $globalVariables;
25 9
        if (Kernel::VERSION_ID >= 40400) {
26 9
            parent::__construct($expressionLanguage);
27
        } else {
28
            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

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