SiteMapController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A SiteMap() 0 8 1
B makeList() 0 21 6
1
<?php
2
namespace WebOfTalent\PageSiteMap;
3
4
use SilverStripe\ErrorPage\ErrorPage;
5
use SilverStripe\Core\Convert;
6
use SilverStripe\ORM\DataObject;
7
8
9
class SiteMapController extends \PageController
10
{
11
    /**
12
    * This function will return a unordered list of all pages on the site.
13
    * Watch for the switch between $page and $child in the second line of the
14
    * foreach().
15
    *
16
    * Note that this will only skip ErrorPage's at the top/root level of the site.
17
    * If you have an ErrorPage class somewhere else in the hierarchy, it will be
18
    * displayed.
19
    */
20
    public function SiteMap()
0 ignored issues
show
Coding Style introduced by
Method name "SiteMapController::SiteMap" is not in camel caps format
Loading history...
21
    {
22
        // Pages at the root level only
23
        $rootLevel = \Page::get()->filter('ParentID', 0);
24
        $output = '';
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
        $output = $this->makeList($rootLevel);
26
        return $output;
27
    }
28
29
    private function makeList($pages)
30
    {
31
        $output = '';
32
        if (count($pages)) {
33
            $output = '
34
			<ul>';
35
            foreach ($pages as $page) {
36
                if (!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title) {
0 ignored issues
show
Bug introduced by
The class SilverStripe\ErrorPage\ErrorPage does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
37
                    $output .= '
38
					<li><a href="'.$page->URLSegment.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
39
                    $whereStatement = 'ParentID = '.$page->ID;
40
                    $childPages = DataObject::get('Page', $whereStatement);
41
                    $output .= $this->makeList($childPages);
42
                    $output .= '</li>';
43
                }
44
            }
45
            $output .= '
46
			</ul>';
47
        }
48
        return $output;
49
    }
50
}
51