Completed
Push — master ( 974d54...5b32eb )
by Nicolaas
01:05
created

SilverstripeColumnsPageControllerExtension   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 132
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 1
dl 12
loc 132
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A HasFullWidthContent() 12 12 4
B HasSideBar() 0 19 6
B NumberOfColumns() 0 24 5
A RecentlyUpdated() 0 18 3
A InThisSection() 0 10 3
A AlsoSee() 0 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    /**
13
     * @return bool
14
     */
15 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...
16
    {
17
        if($this->owner->hasMethod('HasFullWidthContentOverloaded')) {
18
            $v = $this->owner->HasFullWidthContentOverloaded();
19
            if($v !== null) {
20
                return $v;
21
            }
22
        }
23
        if($this->owner->owner->getFullWidthContent()) {
24
            return true;
25
        }
26
    }
27
28
    /**
29
     * @return bool
30
     */
31
    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...
32
    {
33
        if($this->owner->hasMethod('HasSideBarOverloaded')) {
34
            $v = $this->owner->HasSideBarOverloaded();
35
            if($v !== null) {
36
                return $v;
37
            }
38
        }
39
        if(
40
            (
41
                $this->owner->UseDefaultSideBarContent() &&
42
                strlen($this->owner->getMyDefaultSidebarContent()) > 17
43
            )
44
            ||
45
            $this->owner->MySidebarImage()
46
        ) {
47
            return true;
48
        }
49
    }
50
51
52
    /**
53
     * @param boolean $asClassName
54
     *
55
     * @return string | int
56
     */
57
    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...
58
    {
59
        if($this->owner->hasMethod('NumberOfColumnsOverloaded')) {
60
            return $this->owner->NumberOfColumnsOverloaded();
61
            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...
62
                return $v;
63
            }
64
        }
65
        $count = 1;
66
        if($this->owner->HasSideBar()) {
67
            $count++;
68
        }
69
        if($asClassName) {
70
            $array = array(
71
                1 => 'one',
72
                2 => 'two',
73
                3 => 'three'
74
            );
75
            return $array[$count];
76
        }
77
        else {
78
            return $count;
79
        }
80
    }
81
82
83
    /**
84
     * returns a data list of items that have been edited last - up to one day ago.
85
     * This ensures that we do not show stuff we have just fixed up...
86
     * @return DataList
87
     */
88
    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...
89
    {
90
        if($this->owner->hasMethod('RecentlyUpdatedOverloaded')) {
91
            $v = $this->owner->RecentlyUpdatedOverloaded();
92
            if($v !== null) {
93
                return $v;
94
            }
95
        }
96
        return Page::get()
97
            ->filter(
98
                array(
99
                    'ShowInSearch' => true,
100
                    'LastEdited:LessThan' => date('Y-m-d h:i:s', time() - 86400)
101
                )
102
            )
103
            ->sort(array('LastEdited' => 'DESC'))
104
            ->limit($limit);
105
    }
106
107
    /**
108
     * @return null | DataList
109
     */
110
    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...
111
    {
112
        if($this->owner->hasMethod('InThisSectionOverloaded')) {
113
            $v = $this->owner->InThisSectionOverloaded();
114
            if($v !== null) {
115
                return $v;
116
            }
117
        }
118
        return Page::get()->filter(array('ParentID' => $this->owner->ID, 'ShowInMenus' => 1));
119
    }
120
121
    /**
122
     * Siblings
123
     * @return null | DataList
124
     */
125
    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...
126
    {
127
        if($this->owner->hasMethod('AlsoSeeOverloaded')) {
128
            $v = $this->owner->AlsoSeeOverloaded();
129
            if($v !== null) {
130
                return $v;
131
            }
132
        }
133
        if($this->owner->ParentID) {
134
            return Page::get()
135
                ->filter(array('ParentID' => $this->owner->ParentID, 'ShowInMenus' => 1))
136
                ->exclude(array('ID' => $this->owner->ID));
137
        }
138
    }
139
140
}
141