| Conditions | 14 |
| Paths | 14 |
| Total Lines | 59 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 129 | public static function isCurrentLink($source = null, array $aliases = null, $order = false) |
||
| 130 | { |
||
| 131 | $elementPoint = Url::buildPathway($source); |
||
| 132 | $currentPoint = Url::buildPathwayFromRequest(); |
||
| 133 | |||
| 134 | // use special active element order type: controller, action |
||
| 135 | switch ($order) { |
||
| 136 | case 'controller': |
||
| 137 | $elementPoint = Str::firstIn($elementPoint, '/'); |
||
| 138 | $active = Str::startsWith($elementPoint, $currentPoint); |
||
| 139 | break; |
||
| 140 | case 'action': |
||
| 141 | $elementArray = explode('/', $elementPoint); |
||
| 142 | if (!Str::contains('/', $elementPoint) || count($elementArray) < 2) { |
||
| 143 | $active = $elementPoint === $currentPoint; |
||
| 144 | } else { |
||
| 145 | $elementPoint = $elementArray[0] . '/' . $elementArray[1]; |
||
| 146 | $active = Str::startsWith($elementPoint, $currentPoint); |
||
| 147 | } |
||
| 148 | break; |
||
| 149 | case 'id': |
||
| 150 | $elementArray = explode('/', $elementPoint); |
||
| 151 | $elementPoint = $elementArray[0] . '/' . $elementArray[1]; |
||
| 152 | if ($elementArray[2] === null) { // looks like id is not defined in element |
||
| 153 | if (Str::contains('?', $currentPoint)) { |
||
| 154 | $currentPoint = Str::firstIn($currentPoint, '?'); |
||
| 155 | } |
||
| 156 | $currentArray = explode('/', $currentPoint); |
||
| 157 | $currentToId = implode('/', array_slice($currentArray, 0, 3)); |
||
| 158 | $active = $elementPoint === $currentToId; |
||
| 159 | } else { |
||
| 160 | $elementPoint .= '/' . $elementArray[2]; |
||
| 161 | $active = Str::startsWith($elementPoint, $currentPoint); |
||
| 162 | } |
||
| 163 | break; |
||
| 164 | default: |
||
| 165 | $active = $elementPoint === $currentPoint; |
||
| 166 | break; |
||
| 167 | } |
||
| 168 | |||
| 169 | // check if current uri equals with aliases |
||
| 170 | if (Obj::isArray($aliases) && count($aliases) > 0) { |
||
| 171 | foreach ($aliases as $activeUri) { |
||
| 172 | $activeUri = trim($activeUri, '/'); |
||
| 173 | if (Str::endsWith('*', $activeUri)) { |
||
| 174 | $activeUri = rtrim($activeUri, '*'); |
||
| 175 | if (Str::startsWith($activeUri, $currentPoint)) { |
||
| 176 | $active = true; |
||
| 177 | } |
||
| 178 | } else { |
||
| 179 | if ($activeUri === $currentPoint) { |
||
| 180 | $active = true; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | return $active; |
||
| 187 | } |
||
| 188 | |||
| 241 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.