| Conditions | 13 |
| Paths | 12 |
| Total Lines | 53 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 127 | public static function isCurrentLink($source = null, array $aliases = null, $order = false) |
||
| 128 | { |
||
| 129 | $elementPoint = Url::buildPathway($source); |
||
| 130 | $currentPoint = Url::buildPathwayFromRequest(); |
||
| 131 | |||
| 132 | // use special active element order type: controller, action |
||
| 133 | switch ($order) { |
||
| 134 | case 'controller': |
||
| 135 | $elementPoint = Str::firstIn($elementPoint, '/'); |
||
| 136 | $active = Str::startsWith($elementPoint, $currentPoint); |
||
| 137 | break; |
||
| 138 | case 'action': |
||
| 139 | $elementArray = explode('/', $elementPoint); |
||
| 140 | if (!Str::contains('/', $elementPoint) || count($elementArray) < 2) { |
||
| 141 | $active = $elementPoint === $currentPoint; |
||
| 142 | } else { |
||
| 143 | $elementPoint = $elementArray[0] . '/' . $elementArray[1]; |
||
| 144 | $active = Str::startsWith($elementPoint, $currentPoint); |
||
| 145 | } |
||
| 146 | break; |
||
| 147 | case 'id': |
||
| 148 | $elementArray = explode('/', $elementPoint); |
||
| 149 | $elementPoint = $elementArray[0] . '/' . $elementArray[1]; |
||
| 150 | if (null !== $elementArray[2]) { |
||
| 151 | $elementPoint .= '/' . $elementArray[2]; |
||
| 152 | } |
||
| 153 | |||
| 154 | $active = Str::startsWith($elementPoint, $currentPoint); |
||
| 155 | break; |
||
| 156 | default: |
||
| 157 | $active = $elementPoint === $currentPoint; |
||
| 158 | break; |
||
| 159 | } |
||
| 160 | |||
| 161 | // check if current uri equals with aliases |
||
| 162 | if (Obj::isArray($aliases) && count($aliases) > 0) { |
||
| 163 | foreach ($aliases as $activeUri) { |
||
| 164 | $activeUri = trim($activeUri, '/'); |
||
| 165 | if (Str::endsWith('*', $activeUri)) { |
||
| 166 | $activeUri = rtrim($activeUri, '*'); |
||
| 167 | if (Str::startsWith($activeUri, $currentPoint)) { |
||
| 168 | $active = true; |
||
| 169 | } |
||
| 170 | } else { |
||
| 171 | if ($activeUri === $currentPoint) { |
||
| 172 | $active = true; |
||
| 173 | } |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | return $active; |
||
| 179 | } |
||
| 180 | |||
| 221 | } |
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.