DiscoveredFunctions::has()   A
last analyzed

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 1
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
/**
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