| Conditions | 6 |
| Paths | 10 |
| Total Lines | 77 |
| Code Lines | 60 |
| 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 |
||
| 149 | public function execute() |
||
| 150 | { |
||
| 151 | $options = input()->get(); |
||
| 152 | |||
| 153 | if (empty($options)) { |
||
| 154 | $_GET[ 'switch' ] = 'ON'; |
||
| 155 | $_GET[ 'mode' ] = 'default'; |
||
| 156 | $_GET[ 'lifetime' ] = 300; |
||
| 157 | $_GET[ 'title' ] = language()->getLine(strtoupper('CLI_MAINTENANCE_TITLE')); |
||
| 158 | $_GET[ 'message' ] = language()->getLine(strtoupper('CLI_MAINTENANCE_MESSAGE')); |
||
| 159 | } else { |
||
| 160 | $_GET[ 'mode' ] = 'default'; |
||
| 161 | $_GET[ 'lifetime' ] = 300; |
||
| 162 | $_GET[ 'title' ] = language()->getLine(strtoupper('CLI_MAINTENANCE_TITLE')); |
||
| 163 | $_GET[ 'message' ] = language()->getLine(strtoupper('CLI_MAINTENANCE_MESSAGE')); |
||
| 164 | } |
||
| 165 | |||
| 166 | parent::execute(); |
||
| 167 | |||
| 168 | if ($this->optionSwitch === 'ON') { |
||
| 169 | if (cache()->hasItem('maintenance')) { |
||
| 170 | |||
| 171 | $maintenanceInfo = cache()->getItem('maintenance')->get(); |
||
| 172 | output()->write( |
||
|
|
|||
| 173 | (new Format()) |
||
| 174 | ->setContextualClass(Format::DANGER) |
||
| 175 | ->setString(language()->getLine('CLI_MAINTENANCE_ALREADY_STARTED', [ |
||
| 176 | $maintenanceInfo[ 'mode' ], |
||
| 177 | $maintenanceInfo[ 'datetime' ], |
||
| 178 | date('r', strtotime($maintenanceInfo[ 'datetime' ]) + $maintenanceInfo[ 'lifetime' ]), |
||
| 179 | $maintenanceInfo[ 'title' ], |
||
| 180 | $maintenanceInfo[ 'message' ], |
||
| 181 | ])) |
||
| 182 | ->setNewLinesAfter(1) |
||
| 183 | ); |
||
| 184 | } else { |
||
| 185 | output()->write( |
||
| 186 | (new Format()) |
||
| 187 | ->setContextualClass(Format::WARNING) |
||
| 188 | ->setString(language()->getLine('CLI_MAINTENANCE_STARTED', [ |
||
| 189 | $datetime = date('r'), |
||
| 190 | $this->optionLifetime, |
||
| 191 | $this->optionMode, |
||
| 192 | $this->optionTitle, |
||
| 193 | $this->optionMessage, |
||
| 194 | ])) |
||
| 195 | ->setNewLinesAfter(1) |
||
| 196 | ); |
||
| 197 | |||
| 198 | cache()->save(new Item('maintenance', [ |
||
| 199 | 'datetime' => $datetime, |
||
| 200 | 'lifetime' => $this->optionLifetime, |
||
| 201 | 'mode' => $this->optionMode, |
||
| 202 | 'title' => $this->optionTitle, |
||
| 203 | 'message' => $this->optionMessage, |
||
| 204 | ], $this->optionLifetime)); |
||
| 205 | } |
||
| 206 | |||
| 207 | } elseif ($this->optionSwitch === 'OFF') { |
||
| 208 | if (cache()->hasItem('maintenance')) { |
||
| 209 | output()->write( |
||
| 210 | (new Format()) |
||
| 211 | ->setContextualClass(Format::DANGER) |
||
| 212 | ->setString(language()->getLine('CLI_MAINTENANCE_STOPPED', [ |
||
| 213 | $this->optionMode, |
||
| 214 | date('r'), |
||
| 215 | ])) |
||
| 216 | ->setNewLinesAfter(1) |
||
| 217 | ); |
||
| 218 | |||
| 219 | cache()->deleteItem('maintenance'); |
||
| 220 | } else { |
||
| 221 | output()->write( |
||
| 222 | (new Format()) |
||
| 223 | ->setContextualClass(Format::DANGER) |
||
| 224 | ->setString(language()->getLine('CLI_MAINTENANCE_INACTIVE')) |
||
| 225 | ->setNewLinesAfter(1) |
||
| 226 | ); |
||
| 230 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.