Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

SitemapPage_Controller::showpage()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 27
rs 8.439
cc 6
eloc 16
nc 5
nop 1
1
<?php
2
class SitemapPage extends Page {
0 ignored issues
show
Bug introduced by
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
3
4
	private static $description = 'Lists all pages on the site';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
5
6
	private static $singular_name = 'Sitemap Page';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
7
8
	private static $plural_name = 'Sitemap Pages';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
9
10
}
11
class SitemapPage_Controller extends Page_Controller {
0 ignored issues
show
Bug introduced by
The type Page_Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
	private static $allowed_actions = array(
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
14
		'showpage',
15
	);
16
17
	private static $url_handlers = array(
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
18
		'page/$ID' => 'showpage',
19
	);
20
21
	public function Page($link) {
22
		if($link instanceof SS_HTTPRequest) {
23
			Deprecation::notice('2.0', 'Using page() as a url handler is deprecated. Use showpage() action instead');
24
			return $this->showpage($link);
25
		}
26
		return parent::Page($link);
27
	}
28
29
	public function showpage($request) {
30
		$id = (int) $request->param('ID');
31
		if(!$id) {
32
			return false;
33
		}
34
		$page = SiteTree::get()->byId($id);
35
36
		// does the page exist?
37
		if(!($page && $page->exists())) {
38
			return $this->httpError(404);
39
		}
40
41
		// can the page be viewed?
42
		if(!$page->canView()) {
43
			return $this->httpError(403);
44
		}
45
46
		$viewer = $this->customise(array(
47
			'IsAjax' => $request->isAjax(),
48
			'SelectedPage' => $page,
49
			'Children' => $page->Children()
50
		));
51
52
		if($request->isAjax()) {
53
			return $viewer->renderWith('SitemapNodeChildren');
54
		} else {
55
			return $viewer;
56
		}
57
	}
58
59
}
60