| Conditions | 10 |
| Paths | 10 |
| Total Lines | 31 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 10 |
| 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 |
||
| 11 | 6 | public function __construct($value) |
|
| 12 | { |
||
| 13 | 6 | switch (\gettype($value)) { |
|
| 14 | 6 | case 'object': |
|
| 15 | 2 | $class = \get_class($value); |
|
| 16 | 2 | $id = \spl_object_id($value); |
|
| 17 | 2 | $message = "object($class)#$id"; |
|
| 18 | 2 | break; |
|
| 19 | |||
| 20 | 5 | case 'int': |
|
| 21 | 5 | case 'integer': |
|
| 22 | 1 | case 'float': |
|
| 23 | 1 | case 'string': |
|
| 24 | 1 | case 'double': |
|
| 25 | 5 | $message = (string) $value; |
|
| 26 | 5 | break; |
|
| 27 | |||
| 28 | 1 | case 'NULL': |
|
| 29 | 1 | $message = 'null'; |
|
| 30 | 1 | break; |
|
| 31 | |||
| 32 | 1 | case 'boolean': |
|
| 33 | 1 | $message = $value ? 'true' : 'false'; |
|
| 34 | 1 | break; |
|
| 35 | |||
| 36 | default: |
||
| 37 | 1 | $message = \gettype($value); |
|
| 38 | 1 | break; |
|
| 39 | } |
||
| 40 | |||
| 41 | 6 | parent::__construct($message); |
|
| 42 | 6 | } |
|
| 44 |