Completed
Push — master ( df309f...9e12f0 )
by Rafael
08:32
created

FieldExpressionResolver::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Resolver;
12
13
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
14
15
/**
16
 * FieldExpressionResolver
17
 */
18
class FieldExpressionResolver
19
{
20
    /**
21
     * {@inheritDoc}
22
     */
23 1
    public function __invoke(ResolverContext $context, $root)
24
    {
25 1
        $language = new ExpressionLanguage();
26 1
        if ($context->getDefinition()->hasMeta('expression')) {
27 1
            $expression = $context->getDefinition()->getMeta('expression');
28
29 1
            return $language->evaluate(
30 1
                $expression,
31
                [
32 1
                    'this' => $root,
33
                ]
34
            );
35
        }
36
37 1
        return null;
38
    }
39
}
40