| Conditions | 10 |
| Paths | 34 |
| Total Lines | 17 |
| Code Lines | 13 |
| 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 |
||
| 14 | public function eavesdrop($opts = ['criteria' => 0, 'options' => 1], $fnc, $args = []) |
||
| 15 | { |
||
| 16 | if (isset($opts['readArgs']) && !$opts['readArgs']) { |
||
| 17 | $criteria = $opts['criteria'] ?? []; |
||
| 18 | $options = $opts['options'] ?? []; |
||
| 19 | $op = $opts['operation'] ?: null; |
||
| 20 | $name = $opts['name'] ?? $this->name; |
||
|
|
|||
| 21 | } else { |
||
| 22 | $criteria = isset($opts['criteria']) ? $args[$opts['criteria']] ?? [] : []; |
||
| 23 | $options = isset($opts['options']) ? ($args[$opts['options']] ?? []) : []; |
||
| 24 | $op = is_array($fnc) && !isset($opts['operation']) ? |
||
| 25 | ($fnc[1] ?? null) : (isset($opts['operation']) ? ($opts['operation'] ?? null) : null); |
||
| 26 | $name = $opts['name'] ?? $this->name; |
||
| 27 | } |
||
| 28 | |||
| 29 | return $this->analyticalDataCapture($op ?: 'unknownOperation', $criteria, $options, $fnc, $name); |
||
| 30 | } |
||
| 31 | |||
| 84 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: