Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

SitemapBundle/Twig/SitemapTwigExtension.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\SitemapBundle\Twig;
4
5
use Kunstmaan\NodeBundle\Helper\NodeMenuItem;
6
7
class SitemapTwigExtension extends \Twig_Extension
8
{
9
    /**
10
     * Returns a list of functions to add to the existing list.
11
     *
12
     * @return array An array of functions
0 ignored issues
show
Consider making the return type a bit more specific; maybe use \Twig_SimpleFunction[].

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...
13
     */
14
    public function getFunctions()
15
    {
16
        return array(
17
            new \Twig_SimpleFunction('hide_from_sitemap', array($this, 'isHiddenFromSitemap')),
18
            new \Twig_SimpleFunction('hide_children_from_sitemap', array($this, 'isHiddenChildrenFromSitemap')),
19
        );
20
    }
21
22
    /**
23
     * Returns true when the item should be hidden from the sitemap
24
     *
25
     * @param NodeMenuItem $item
26
     *
27
     * @return \Kunstmaan\NodeBundle\Helper\NodeMenuItem
28
     */
29 View Code Duplication
    public function isHiddenFromSitemap(NodeMenuItem $item)
30
    {
31
        if (is_subclass_of($item->getNode()->getRefEntityName(), 'Kunstmaan\\SitemapBundle\\Helper\\HiddenFromSitemapInterface')) {
32
            $page = $item->getPage();
33
34
            return $page->isHiddenFromSitemap();
35
        }
36
37
        return false;
38
    }
39
40
    /**
41
     * Returns true when the children of the item should be hidden from the sitemap
42
     *
43
     * @param NodeMenuItem $item
44
     *
45
     * @return bool
46
     */
47 View Code Duplication
    public function isHiddenChildrenFromSitemap(NodeMenuItem $item)
48
    {
49
        if (is_subclass_of($item->getNode()->getRefEntityName(), 'Kunstmaan\\SitemapBundle\\Helper\\HiddenFromSitemapInterface')) {
50
            $page = $item->getPage();
51
52
            return $page->isChildrenHiddenFromSitemap();
53
        }
54
55
        return false;
56
    }
57
}
58