ExplanationPage_Controller::getItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class ExplanationPage 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
6
    public static $has_many = array(
7
        'Explanations' => 'Explanation'
8
    );
9
10
11 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
    {
13
        $fields = parent::getCMSFields();
14
15
        $conf = GridFieldConfig_RecordEditor::create();
16
        $grid = GridField::create('Explanations', $this->fieldLabel('Explanations'), $this->Explanations(), $conf);
17
        $tabTitle = $this->fieldLabel('Explanations');
18
        $fields->addFieldsToTab('Root.' . $tabTitle, $grid);
19
20
        return $fields;
21
    }
22
}
23
24
class ExplanationPage_Controller extends AbbreviationPage_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...
25
{
26
    private static $url_handlers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_handlers is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
        '$Item!' => 'viewItem'
28
    );
29
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
        'viewItem'
31
    );
32
33 View Code Duplication
    public function viewItem()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $item = $this->getItem($this->request->param('Item'));
36
        if (!$item) {
37
            $this->httpError(404);
38
        }
39
        return $this->customise(array('Item' => $item))->renderWith(array('ExplanationPage_view', 'Page'));
40
    }
41
42
    public function getItem($slug)
43
    {
44
        return Explanation::get()->filter(array('URLSlug' => $slug))->first();
45
    }
46
47
    public function getItems()
48
    {
49
        return Explanation::get()->sort('Title');
50
    }
51
}
52