Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

getPossibleChildTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Kunstmaan\NodeBundle\Twig;
4
5
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
6
use Kunstmaan\NodeBundle\Helper\PagesConfiguration;
7
use Twig\Extension\AbstractExtension;
8
use Twig\TwigFunction;
9
10
/**
11
 * @final since 5.4
12
 */
13
class PagesConfigurationTwigExtension extends AbstractExtension
14
{
15
    /** @var PagesConfiguration */
16
    private $pagesConfiguration;
17
18
    /**
19
     * @param PagesConfiguration $pagesConfiguration
20
     */
21
    public function __construct(PagesConfiguration $pagesConfiguration)
22
    {
23
        $this->pagesConfiguration = $pagesConfiguration;
24
    }
25
26
    /**
27
     * Returns a list of functions to add to the existing list.
28
     *
29
     * @return array An array of functions
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,TwigFunction>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
30
     */
31
    public function getFunctions()
32
    {
33
        return [
34
            'get_possible_child_types' => new TwigFunction(
35
                'get_possible_child_types', [$this, 'getPossibleChildTypes']
36
            ),
37
            'get_homepage_types' => new TwigFunction(
38
                'get_homepage_types', [$this, 'getHomepageTypes']
39
            ),
40
        ];
41
    }
42
43
    /**
44
     * @param string|HasNodeInterface $reference
45
     *
46
     * @return array
47
     */
48
    public function getPossibleChildTypes($reference)
49
    {
50
        return $this->pagesConfiguration->getPossibleChildTypes($reference);
0 ignored issues
show
Bug introduced by
It seems like $reference defined by parameter $reference on line 48 can also be of type object<Kunstmaan\NodeBun...ntity\HasNodeInterface>; however, Kunstmaan\NodeBundle\Hel...getPossibleChildTypes() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getHomepageTypes()
57
    {
58
        return $this->pagesConfiguration->getHomepageTypes();
59
    }
60
}
61