SitemapPageController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A showpage() 0 32 6
1
<?php
2
3
namespace CWP\CWP\PageTypes;
4
5
use PageController;
0 ignored issues
show
Bug introduced by
The type PageController 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...
6
use SilverStripe\CMS\Model\SiteTree;
7
8
class SitemapPageController extends PageController
9
{
10
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
11
        'showpage',
12
    ];
13
14
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
15
        'page/$ID' => 'showpage',
16
    ];
17
18
    public function showpage($request)
19
    {
20
        $id = (int) $request->param('ID');
21
        if (!$id) {
22
            return false;
23
        }
24
        $page = SiteTree::get()->byId($id);
25
26
        // does the page exist?
27
        if (!($page && $page->exists())) {
28
            return $this->httpError(404);
29
        }
30
31
        // can the page be viewed?
32
        if (!$page->canView()) {
33
            return $this->httpError(403);
34
        }
35
36
        $viewer = $this->customise([
37
            'IsAjax' => $request->isAjax(),
38
            'SelectedPage' => $page,
39
            'Children' => $page->Children(),
40
        ]);
41
42
        if ($request->isAjax()) {
43
            return $viewer->renderWith([
44
                'type' => 'Includes',
45
                'SitemapNodeChildren'
46
            ]);
47
        }
48
49
        return $viewer;
50
    }
51
}
52