BasicSerializerFunctionsProvider::getFunctions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
crap 1
1
<?php
2
3
namespace JMS\SerializerBundle\ExpressionLanguage;
4
5
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
6
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
7
8
class BasicSerializerFunctionsProvider implements ExpressionFunctionProviderInterface
9
{
10 11
    public function getFunctions()
11
    {
12
        return [
13
            new ExpressionFunction('service', function ($arg) {
14 1
                return sprintf('$this->get(%s)', $arg);
15
            }, function (array $variables, $value) {
16 1
                return $variables['container']->get($value);
17 11
            }),
18
            new ExpressionFunction('parameter', function ($arg) {
19 1
                return sprintf('$this->getParameter(%s)', $arg);
20
            }, function (array $variables, $value) {
21 1
                return $variables['container']->getParameter($value);
22 11
            }),
23
            new ExpressionFunction('is_granted', function ($attribute, $object = null) {
24 1
                return sprintf('call_user_func_array(array($this->get(\'security.authorization_checker\'), \'isGranted\'), array(%s, %s))', $attribute, $object);
25 11
            }, function (array $variables, $attribute, $object = null) {
26 1
                return call_user_func_array(
27 1
                    array($variables['container']->get('security.authorization_checker'), 'isGranted'),
28 1
                    [$attribute, $object]
29 1
                );
30 11
            }),
31 11
        ];
32
    }
33
}
34