Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

Twig/PagesConfigurationTwigExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    public function __construct(PagesConfiguration $pagesConfiguration)
19
    {
20
        $this->pagesConfiguration = $pagesConfiguration;
21
    }
22
23
    /**
24
     * Returns a list of functions to add to the existing list.
25
     *
26
     * @return array An array of functions
0 ignored issues
show
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...
27
     */
28
    public function getFunctions()
29
    {
30
        return [
31
            'get_possible_child_types' => new TwigFunction(
32
                'get_possible_child_types', [$this, 'getPossibleChildTypes']
33
            ),
34
            'get_homepage_types' => new TwigFunction(
35
                'get_homepage_types', [$this, 'getHomepageTypes']
36
            ),
37
        ];
38
    }
39
40
    /**
41
     * @param string|HasNodeInterface $reference
42
     *
43
     * @return array
44
     */
45
    public function getPossibleChildTypes($reference)
46
    {
47
        return $this->pagesConfiguration->getPossibleChildTypes($reference);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getHomepageTypes()
54
    {
55
        return $this->pagesConfiguration->getHomepageTypes();
56
    }
57
}
58