SiteMapPage_Controller::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
4
/**
5
 * @author Nicolaas [at] sunnysideup.co.nz
6
 *
7
 *
8
 **/
9
10
11
class SiteMapPage extends Page
0 ignored issues
show
Coding Style Compatibility introduced by
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...
12
{
13
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db 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...
14
        "ShowAllPages" => "Boolean"
15
    );
16
17
    private static $description = "Sitemap Page: shows all the pages of a site in a tree format";
0 ignored issues
show
Unused Code introduced by
The property $description 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...
18
19
    private static $add_action = 'Site Map Page';
0 ignored issues
show
Unused Code introduced by
The property $add_action 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...
20
21
    private static $icon = 'sitemappage/images/treeicons/SiteMapPage';
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
22
23
    public function canCreate($member = null)
24
    {
25
        return ! SiteMapPage::get()->count();
26
    }
27
28
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
29
    {
30
        $fields = parent::getCMSFields();
31
        $fields->addFieldToTab("Root.Display", new CheckboxField("ShowAllPages", "Show all pages from the start"));
32
        return $fields;
33
    }
34
}
35
36
class SiteMapPage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
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...
37
{
38
    public function init()
39
    {
40
        parent::init();
41
        if (!$this->ShowAllPages) {
42
            Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
43
            Requirements::javascript('sitemappage/javascript/SiteMapPage.js');
44
            Requirements::themedCSS('SiteMapPage', "sitemappage");
45
        } else {
46
            Requirements::themedCSS('SiteMapPageOpen', "sitemappage");
47
        }
48
    }
49
50
    public function LevelOneSiteMapPages()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
51
    {
52
        $homePage = SiteTree::get()->filter(array("ParentID" => 0))->first();
53
        return $homePage->SiteMapPages($noParent = true);
54
    }
55
}
56