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

Completed
Pull Request — master (#698)
by Jérémiah
26:27 queued 23:47
created

ExpressionValidator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 10
cc 2
nc 2
nop 2
crap 2.0185
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\Generator\TypeGenerator;
9
use Overblog\GraphQLBundle\Validator\ValidationNode;
10
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
11
use Symfony\Component\HttpKernel\Kernel;
12
use Symfony\Component\Validator\Constraint;
13
use Symfony\Component\Validator\Constraints\Expression;
14
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
15
16
class ExpressionValidator extends \Symfony\Component\Validator\Constraints\ExpressionValidator
17
{
18
    private ExpressionLanguage $expressionLanguage;
19
20
    private GlobalVariables $globalVariables;
21
22 9
    public function __construct(ExpressionLanguage $expressionLanguage, GlobalVariables $globalVariables)
23
    {
24 9
        $this->expressionLanguage = $expressionLanguage;
25 9
        $this->globalVariables = $globalVariables;
26 9
        if (Kernel::VERSION_ID >= 40400) {  // @phpstan-ignore-line
27 9
            parent::__construct($expressionLanguage);
28
        } else {                            // @phpstan-ignore-line
29
            parent::{'__construct'}(null, $expressionLanguage);
30
        }
31 9
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 9
    public function validate($value, Constraint $constraint): void
37
    {
38 9
        if (!$constraint instanceof Expression) {
39
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression');
40
        }
41
42 9
        $variables = $constraint->values;
43 9
        $variables['value'] = $value;
44 9
        $variables[TypeGenerator::GLOBAL_VARS] = $this->globalVariables;
45
46 9
        $object = $this->context->getObject();
47
48 9
        $variables['this'] = $object;
49
50 9
        if ($object instanceof ValidationNode) {
51 9
            $variables['parentValue'] = $object->getResolverArg('value');
52 9
            $variables['context'] = $object->getResolverArg('context');
53 9
            $variables['args'] = $object->getResolverArg('args');
54 9
            $variables['info'] = $object->getResolverArg('info');
55
        }
56
57 9
        if (!$this->expressionLanguage->evaluate($constraint->expression, $variables)) {
58 4
            $this->context->buildViolation($constraint->message)
59 4
                          ->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
60 4
                          ->setCode(Expression::EXPRESSION_FAILED_ERROR)
61 4
                          ->addViolation();
62
        }
63 9
    }
64
}
65