Completed
Push — master ( 63cfe4...886ab6 )
by Nicolaas
01:32
created

SitemapPageDecorator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 59
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B SiteMapPages() 0 24 6
1
<?php
2
3
class SitemapPageDecorator extends SiteTreeExtension
0 ignored issues
show
Coding Style Compatibility introduced by sunnysideup
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    /**
7
     * Note, you have to list each class explicitely
8
     * That is, descendants need to be listed as well
9
     * as their parents, to exclude them both.
10
     *
11
     * Includes override excludes.  If you list includes,
12
     * then only those pages will be shown.
13
     * If you dont list includes, then the exclude list will be
14
     * used and if this is empty all page types will be included.
15
     *
16
     * @var Array
17
     */
18
    private static $sitemap_classes_to_exclude = array("ErrorPage");
0 ignored issues
show
Unused Code introduced by sunnysideup
The property $sitemap_classes_to_exclude is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
20
    /**
21
     * Note, you have to list each class explicitely
22
     * That is, descendants need to be listed as well
23
     * as their parents, to exclude them both.
24
     *
25
     * Includes override excludes.  If you list includes,
26
     * then only those pages will be shown.
27
     * If you dont list includes, then the exclude list will be
28
     * used and if this is empty all page types will be included.
29
     *
30
     * @var Array
31
     */
32
    private static $sitemap_classes_to_include = array();
0 ignored issues
show
Unused Code introduced by sunnysideup
The property $sitemap_classes_to_include is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
33
34
    /**
35
     * @return DataList
36
     */
37
    public function SiteMapPages($noParent = false)
38
    {
39
        if ($noParent) {
40
            $parentID = 0;
41
        } else {
42
            $parentID = $this->owner->ID;
43
        }
44
        $filterArray = array(
45
            "ParentID" => $parentID,
46
            "ShowInMenus" => 1,
47
            "ShowInSearch" => 1
48
        );
49
        $excludeArray = array("ClassName" => 'SiteMapPage');
50
        $inc = Config::inst()->get("SitemapPageDecorator", "sitemap_classes_to_include");
51
        $exc = Config::inst()->get("SitemapPageDecorator", "sitemap_classes_to_exclude");
52
        if (is_array($inc) && count($inc)) {
53
            $filterArray["ClassName"] = $inc;
54
        } elseif (is_array($exc) && count($exc)) {
55
            $excludeArray["ClassName"] = $exc;
56
        }
57
        return SiteTree::get()
58
            ->filter($filterArray)
59
            ->exclude($excludeArray);
60
    }
61
}
62