| Conditions | 10 |
| Paths | 10 |
| Total Lines | 37 |
| Code Lines | 26 |
| 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 |
||
| 20 | public static function fromInvalidCallable( |
||
| 21 | array $inProgressMakes, |
||
| 22 | $callableOrMethodStr, |
||
| 23 | \Exception $previous = null |
||
| 24 | ) { |
||
| 25 | $callableString = null; |
||
| 26 | |||
| 27 | if (is_string($callableOrMethodStr)) { |
||
| 28 | $callableString .= $callableOrMethodStr; |
||
| 29 | } else if (is_array($callableOrMethodStr) && |
||
| 30 | array_key_exists(0, $callableOrMethodStr) && |
||
| 31 | array_key_exists(0, $callableOrMethodStr)) { |
||
| 32 | if (is_string($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) { |
||
| 33 | $callableString .= $callableOrMethodStr[0].'::'.$callableOrMethodStr[1]; |
||
| 34 | } else if (is_object($callableOrMethodStr[0]) && is_string($callableOrMethodStr[1])) { |
||
| 35 | $callableString .= sprintf( |
||
| 36 | "[object(%s), '%s']", |
||
| 37 | get_class($callableOrMethodStr[0]), |
||
| 38 | $callableOrMethodStr[1] |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | if ($callableString) { |
||
|
|
|||
| 44 | // Prevent accidental usage of long strings from filling logs. |
||
| 45 | $callableString = substr($callableString, 0, 250); |
||
| 46 | $message = sprintf( |
||
| 47 | "%s. Invalid callable was '%s'", |
||
| 48 | Injector::M_INVOKABLE, |
||
| 49 | $callableString |
||
| 50 | ); |
||
| 51 | } else { |
||
| 52 | $message = \Atreyu\Injector::M_INVOKABLE; |
||
| 53 | } |
||
| 54 | |||
| 55 | return new self($inProgressMakes, $message, Injector::E_INVOKABLE, $previous); |
||
| 56 | } |
||
| 57 | |||
| 68 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: