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

SitemapBundle/Twig/SitemapTwigExtension.php (3 issues)

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
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFunction;
8
9
/**
10
 * @final since 5.4
11
 */
12
class SitemapTwigExtension extends AbstractExtension
13
{
14
    /**
15
     * Returns a list of functions to add to the existing list.
16
     *
17
     * @return array An array of functions
0 ignored issues
show
Consider making the return type a bit more specific; maybe use 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...
18
     */
19
    public function getFunctions()
20
    {
21
        return array(
22
            new TwigFunction('hide_from_sitemap', array($this, 'isHiddenFromSitemap')),
23
            new TwigFunction('hide_children_from_sitemap', array($this, 'isHiddenChildrenFromSitemap')),
24
        );
25
    }
26
27
    /**
28
     * Returns true when the item should be hidden from the sitemap
29
     *
30
     * @param NodeMenuItem $item
31
     *
32
     * @return \Kunstmaan\NodeBundle\Helper\NodeMenuItem
33
     */
34 View Code Duplication
    public function isHiddenFromSitemap(NodeMenuItem $item)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        if (is_subclass_of($item->getNode()->getRefEntityName(), 'Kunstmaan\\SitemapBundle\\Helper\\HiddenFromSitemapInterface')) {
37
            $page = $item->getPage();
38
39
            return $page->isHiddenFromSitemap();
40
        }
41
42
        return false;
43
    }
44
45
    /**
46
     * Returns true when the children of the item should be hidden from the sitemap
47
     *
48
     * @param NodeMenuItem $item
49
     *
50
     * @return bool
51
     */
52 View Code Duplication
    public function isHiddenChildrenFromSitemap(NodeMenuItem $item)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        if (is_subclass_of($item->getNode()->getRefEntityName(), 'Kunstmaan\\SitemapBundle\\Helper\\HiddenFromSitemapInterface')) {
55
            $page = $item->getPage();
56
57
            return $page->isChildrenHiddenFromSitemap();
58
        }
59
60
        return false;
61
    }
62
}
63