DiscoveredFunctions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 48
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 3 1
A resolveArguments() 0 14 3
A has() 0 3 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[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 Yarhon\RouteGuardBundle\Twig\NodeVisitor;
12
13
use Twig\Node\Node;
14
15
/**
16
 * @author Yaroslav Honcharuk <[email protected]>
17
 */
18
class DiscoveredFunctions
19
{
20
    /**
21
     * @var array
22
     */
23
    private $functions = [
24
        'url',
25
        'path',
26
    ];
27
28
    /**
29
     * @param string $functionName
30
     *
31
     * @return bool
32
     */
33 4
    public function has($functionName)
34
    {
35 4
        return in_array($functionName, $this->functions, true);
36
    }
37
38
    /**
39
     * @param string $functionName
40
     * @param Node[] $functionArguments
41
     *
42
     * @return array array of 2 elements: RouteExpression arguments and generateAs parameters
43
     */
44 3
    public function resolveArguments($functionName, $functionArguments)
45
    {
46 3
        $arguments = [$functionArguments[0]];
47 3
        $generateAs = [$functionName];
48
49 3
        if (isset($functionArguments[1])) {
50 1
            $arguments[1] = $functionArguments[1];
51
        }
52
53 3
        if (isset($functionArguments[2])) {
54 1
            $generateAs[1] = $functionArguments[2];
55
        }
56
57 3
        return [$arguments, $generateAs];
58
    }
59
60
    /**
61
     * @return array
62
     */
63 2
    public function getFunctions()
64
    {
65 2
        return $this->functions;
66
    }
67
}
68