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 (#536)
by
unknown
21:14
created

ExpressionValidator::getExpressionLanguage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 0
crap 12
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\Validator\Constraint;
10
use Symfony\Component\Validator\Constraints\Expression;
11
use Symfony\Component\Validator\Exception\LogicException;
12
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
13
14
class ExpressionValidator extends \Symfony\Component\Validator\Constraints\ExpressionValidator
15
{
16
    private $expressionLanguage;
17
18
    public function __construct(ExpressionLanguage $expressionLanguage = null)
19
    {
20
        $this->expressionLanguage = $expressionLanguage;
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function validate($value, Constraint $constraint): void
27
    {
28
        if (!$constraint instanceof Expression) {
29
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Expression');
30
        }
31
32
        $variables = $constraint->values;
33
        $variables['value'] = $value;
34
35
        $object = $this->context->getObject();
36
37
        $variables['this'] = $object;
38
39
        if ($object instanceof ValidationNode) {
40
            $variables['prevValue'] = $object->getResolverArg('value');
41
            $variables['context'] = $object->getResolverArg('context');
42
            $variables['args'] = $object->getResolverArg('args');
43
            $variables['info'] = $object->getResolverArg('info');
44
        }
45
46
        if (!$this->getExpressionLanguage()->evaluate($constraint->expression, $variables)) {
47
            $this->context->buildViolation($constraint->message)
48
                ->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
49
                ->setCode(Expression::EXPRESSION_FAILED_ERROR)
50
                ->addViolation();
51
        }
52
    }
53
54
    private function getExpressionLanguage()
55
    {
56
        if (null === $this->expressionLanguage) {
57
            if (!\class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
58
                throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
59
            }
60
            $this->expressionLanguage = new ExpressionLanguage();
61
        }
62
63
        return $this->expressionLanguage;
64
    }
65
}
66