Completed
Push — master ( 9b2b5e...32f380 )
by Gordon
06:13
created

SiteMap_Controller::makeList()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6
Metric Value
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 8.5906
cc 6
eloc 14
nc 2
nop 1
crap 6
1
<?php
2
3
class SiteMap 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...
4
{
5
  // hide from menus and search
6
  public static $defaults = array(
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 4 spaces, but found 2).
Loading history...
7
    'ShowInMenus' => 0,
8
    'ShowInSearch' => 0,
9
  );
10
}
11
12
class SiteMap_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...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
13
{
14
	/**
15
	* This function will return a unordered list of all pages on the site.
16
	* Watch for the switch between $page and $child in the second line of the
17
	* foreach().
18
	*
19
	* Note that this will only skip ErrorPage's at the top/root level of the site.
20
	* If you have an ErrorPage class somewhere else in the hierarchy, it will be
21
	* displayed.
22
	*/
23 1
	public function SiteMap()
0 ignored issues
show
Coding Style introduced by
Method name "SiteMap_Controller::SiteMap" is not in camel caps format
Loading history...
24
	{
25
		// Pages at the root level only
26 1
		$rootLevel = DataObject::get('Page', 'ParentID = 0');
27 1
		$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...
28 1
		$output = $this->makeList($rootLevel);
29 1
		return $output;
30
	}
31
32 1
	private function makeList($pages)
33
	{
34 1
		$output = '';
35 1
		if (count($pages)) {
36
			$output = '
37 1
			<ul class="sitemap-list">';
38 1
			foreach ($pages as $page) {
39 1
				if (!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title) {
40
					$output .= '
41 1
					<li><a href="'.$page->URLSegment.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
42 1
					$whereStatement = 'ParentID = '.$page->ID;
43
					//$childPages = new DataObjectSet();
44 1
					$childPages = DataObject::get('Page', $whereStatement);
45 1
					$output .= $this->makeList($childPages);
46
					$output .= '
47 1
					</li>';
48 1
				}
49 1
			}
50
			$output .= '
51 1
			</ul>';
52 1
		}
53 1
		return $output;
54
	}
55
}
56