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:13
created

ExpressionValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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