Conditions | 13 |
Paths | 13 |
Total Lines | 53 |
Code Lines | 25 |
Lines | 13 |
Ratio | 24.53 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function addToSiteMenu (&$pageView) |
||
63 | { |
||
64 | $frontMatter = $pageView->getFrontMatter(); |
||
65 | |||
66 | if (isset($frontMatter['menu']) && !$frontMatter['menu']) |
||
67 | { |
||
68 | return; |
||
69 | } |
||
70 | |||
71 | $url = trim($pageView->getPermalink(), '/'); |
||
72 | |||
73 | // @TODO in the next breaking release, remove this check and allow the homepage to be indexed as '.' |
||
74 | if (empty($url)) |
||
75 | { |
||
76 | return; |
||
77 | } |
||
78 | |||
79 | $root = &$this->siteMenu; |
||
80 | $dirs = explode('/', $url); |
||
81 | |||
82 | while (count($dirs) > 0) |
||
83 | { |
||
84 | $name = array_shift($dirs); |
||
85 | $name = (!empty($name)) ? $name : '.'; |
||
86 | |||
87 | if (!is_null($name) && count($dirs) == 0) |
||
88 | { |
||
89 | View Code Duplication | if (isset($root[$name]) && is_array($root[$name])) |
|
90 | { |
||
91 | $children = &$pageView->getChildren(); |
||
92 | $children = $root[$name]['children']; |
||
93 | } |
||
94 | |||
95 | $root[$name] = &$pageView; |
||
96 | } |
||
97 | else |
||
98 | { |
||
99 | if (!isset($root[$name])) |
||
100 | { |
||
101 | $root[$name]['children'] = array(); |
||
102 | $root = &$root[$name]['children']; |
||
103 | } |
||
104 | View Code Duplication | else if (isset($root[$name]) && is_array($root[$name])) |
|
105 | { |
||
106 | $root = &$root[$name]['children']; |
||
107 | } |
||
108 | else |
||
109 | { |
||
110 | $root = &$root[$name]->getChildren(); |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..