Completed
Branch master (c0d8ef)
by Yaroslav
06:36
created

DiscoveredFunctions   A

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
class DiscoveredFunctions
16
{
17
    /**
18
     * @var array
19
     */
20
    private $functions = [
21
        'url',
22
        'path',
23
    ];
24
25
    /**
26
     * @param string $functionName
27
     *
28
     * @return bool
29
     */
30 4
    public function has($functionName)
31
    {
32 4
        return in_array($functionName, $this->functions, true);
33
    }
34
35
    /**
36
     * @param string $functionName
37
     * @param Node[] $functionArguments
38
     *
39
     * @return array array of 2 elements: RouteExpression arguments and generateAs parameters
40
     */
41 3
    public function resolveArguments($functionName, $functionArguments)
42
    {
43 3
        $arguments = [$functionArguments[0]];
44 3
        $generateAs = [$functionName];
45
46 3
        if (isset($functionArguments[1])) {
47 1
            $arguments[1] = $functionArguments[1];
48
        }
49
50 3
        if (isset($functionArguments[2])) {
51 1
            $generateAs[1] = $functionArguments[2];
52
        }
53
54 3
        return [$arguments, $generateAs];
55
    }
56
57
    /**
58
     * @return array
59
     */
60 2
    public function getFunctions()
61
    {
62 2
        return $this->functions;
63
    }
64
}
65