Completed
Push — master ( a6e78f...99b8ba )
by Nicolaas
01:11
created

myspecificpagemenuitems()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
/**
4
 *@author nicolaas [at] sunnysideup.co.nz
5
 *
6
 *
7
 **/
8
9
class SilverstripeColumnsPageControllerExtension extends Extension
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...
10
{
11
12
    private static $allowed_actions = [
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...
13
        'myspecificpagemenuitems' => true
14
    ];
15
16
    /**
17
     * @return bool
18
     */
19 View Code Duplication
    function HasFullWidthContent()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

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...
20
    {
21
        if($this->owner->hasMethod('HasFullWidthContentOverloaded')) {
22
            $v = $this->owner->HasFullWidthContentOverloaded();
23
            if($v !== null) {
24
                return $v;
25
            }
26
        }
27
        if($this->owner->owner->getFullWidthContent()) {
28
            return true;
29
        }
30
    }
31
32
    /**
33
     * @return bool
34
     */
35
    function HasSideBar()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
36
    {
37
        if($this->owner->hasMethod('HasSideBarOverloaded')) {
38
            $v = $this->owner->HasSideBarOverloaded();
39
            if($v !== null) {
40
                return $v;
41
            }
42
        }
43
        if(
44
            (
45
                $this->owner->UseDefaultSideBarContent() &&
46
                strlen($this->owner->getMyDefaultSidebarContent()) > 17
47
            )
48
            ||
49
            $this->owner->MySidebarImage()
50
        ) {
51
            return true;
52
        }
53
    }
54
55
    /**
56
     * @param boolean $asClassName
57
     *
58
     * @return string | int
59
     */
60
    function NumberOfColumns($asClassName = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
61
    {
62
        if($this->owner->hasMethod('NumberOfColumnsOverloaded')) {
63
            return $this->owner->NumberOfColumnsOverloaded();
64
            if($v !== null) {
0 ignored issues
show
Unused Code introduced by
if ($v !== null) { return $v; } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
65
                return $v;
66
            }
67
        }
68
        $count = 1;
69
        if($this->owner->HasSideBar()) {
70
            $count++;
71
        }
72
        if($asClassName) {
73
            $array = array(
74
                1 => 'one',
75
                2 => 'two',
76
                3 => 'three'
77
            );
78
            return $array[$count];
79
        }
80
        else {
81
            return $count;
82
        }
83
    }
84
85
86
    /**
87
     * returns a data list of items that have been edited last - up to one day ago.
88
     * This ensures that we do not show stuff we have just fixed up...
89
     * @return DataList
90
     */
91
    function RecentlyUpdated($limit = 5)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
92
    {
93
        if($this->owner->hasMethod('RecentlyUpdatedOverloaded')) {
94
            $v = $this->owner->RecentlyUpdatedOverloaded();
95
            if($v !== null) {
96
                return $v;
97
            }
98
        }
99
        return Page::get()
100
            ->filter(
101
                array(
102
                    'ShowInSearch' => true,
103
                    'LastEdited:LessThan' => date('Y-m-d h:i:s', time() - 86400)
104
                )
105
            )
106
            ->sort(array('LastEdited' => 'DESC'))
107
            ->limit($limit);
108
    }
109
110
    /**
111
     *  Children Menu Items
112
     * @return null | DataList
113
     */
114 View Code Duplication
    function InThisSection()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

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...
115
    {
116
        if($this->owner->hasMethod('InThisSectionOverloaded')) {
117
            $v = $this->owner->InThisSectionOverloaded();
118
            if($v !== null) {
119
                return $v;
120
            }
121
        }
122
        
123
        return $this->owner->ChildrenShowInMenu();
124
    }
125
126
    /**
127
     * Sibling Menu Items
128
     * @return null | DataList
129
     */
130
    function AlsoSee()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
131
    {
132
        if($this->owner->hasMethod('AlsoSeeOverloaded')) {
133
            $v = $this->owner->AlsoSeeOverloaded();
134
            if($v !== null) {
135
                return $v;
136
            }
137
        }
138
        if($this->owner->ParentID) {
139
            $parent = DataObject::get_one('Page', ['ParentID' => $this->owner->ParentID]);
140
            $list = $parent->ChildrenShowInMenu();
141
            $list->removeByID($this->owner->ID);
142
143
            return $list;
144
145
        }
146
    }
147
148
    /**
149
     * returns relevant menus items for
150
     * @param  SS_Request
151
     * @return string (html)
152
     */
153
    function myspecificpagemenuitems($request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
154
    {
155
        if($this->owner->hasMethod('MySpecificPageMenuItemsOverloaded')) {
156
            $v = $this->owner->MySpecificPageMenuItemsOverloaded();
157
            if($v !== null) {
158
                return $v;
159
            }
160
        }
161
        $id = intval($this->owner->request->param('ID'));
162
        $page = Page::get()->byID($id);
163
164
        return $page->renderWith('MyMenuItems');
165
    }
166
167
168
}
169