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

DiscoveredFunctions::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 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