TaxonomyDirectoryController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 16
c 2
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 12 1
A renderBreadcrumb() 0 8 1
1
<?php
2
3
namespace SilverStripe\Taxonomy\Controllers;
4
5
use 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...
6
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...
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\ORM\ArrayList;
9
use SilverStripe\View\ArrayData;
10
use SilverStripe\View\SSViewer;
11
12
if (!class_exists(PageController::class)) {
13
    return;
14
}
15
16
/**
17
 * Class TaxonomyDirectoryController
18
 *
19
 * Controller for returning a list of pages tagged with a specific Taxonomy Term
20
 */
21
class TaxonomyDirectoryController extends PageController
22
{
23
24
    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...
25
        'index'
26
    );
27
28
    public function index(HTTPRequest $request)
29
    {
30
        $termString = $request->param('ID');
31
32
        $pages = Page::get()->filter(['Terms.Name' => $termString]);
33
34
        return $this->customise(new ArrayData(array(
35
            'Title' => $termString,
36
            'Term' => $termString,
37
            'Pages' => $pages,
38
            'Breadcrumbs' => $this->renderBreadcrumb($termString)
39
        )))->renderWith(array(__CLASS__, "Page"));
40
    }
41
42
    protected function renderBreadcrumb($termString)
43
    {
44
        $page = new Page();
45
        $page->Title = $termString;
46
47
        $template = new SSViewer('BreadcrumbsTemplate');
48
        return $template->process($this->customise(new ArrayData(array(
49
            "Pages" => new ArrayList(array($page))
50
        ))));
51
    }
52
}
53