Completed
Push — location_references ( 47d67d )
by
unknown
13:55
created

ExpressionLanguageProvider::getFunctions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 59
rs 8.8945
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace eZ\Publish\Core\LocationReference\ExpressionLanguage;
6
7
use eZ\Publish\API\Repository\Values\Content\Location;
8
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
9
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
10
11
final class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
12
{
13
    public function getFunctions(): array
14
    {
15
        return [
16
            new ExpressionFunction(
17
                'remote_id',
18
                function (string $args): string {
19
                    return sprintf('$__location_service->loadLocationByRemoteId(%s)', $args);
20
                },
21
                function (array $variables, string $remoteId): Location {
22
                    return $variables['__location_service']->loadLocationByRemoteId($remoteId);
23
                }
24
            ),
25
            new ExpressionFunction(
26
                'local_id',
27
                function (string $args): string {
28
                    return sprintf('$__location_service->loadLocation(%s)', $args);
29
                },
30
                function (array $variables, int $id): Location {
31
                    return $variables['__location_service']->loadLocation($id);
32
                }
33
            ),
34
            new ExpressionFunction(
35
                'path',
36
                function (string $args): string {
37
                    return sprintf('$__location_service->loadLocationByPathString(%s)', $args);
38
                },
39
                function (array $variables, string $path): Location {
40
                    return $variables['__location_service']->loadLocationByPathString($path);
41
                }
42
            ),
43
            new ExpressionFunction(
44
                'parent',
45
                function (string $args): string {
46
                    return sprintf('$__location_service->loadParentLocation(%s)', $args);
47
                },
48
                function (array $variables, Location $location): Location {
49
                    return $variables['__location_service']->loadParentLocation($location);
50
                }
51
            ),
52
            new ExpressionFunction(
53
                'root',
54
                function (string $args): string {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
                    return '$__self->resolve($___named_references->getReference("__root"))';
56
                },
57
                function (array $variables): Location {
58
                    return $variables['__self']->resolve($variables['__named_references']->getReference('__root'));
59
                }
60
            ),
61
            new ExpressionFunction(
62
                'named',
63
                function (string $args): string {
64
                    return sprintf('$__self->resolve($___named_references->getReference(%s))', $args);
65
                },
66
                function (array $variables, string $name): Location {
67
                    return $variables['__self']->resolve($variables['__named_references']->getReference($name));
68
                }
69
            ),
70
        ];
71
    }
72
}
73