| Conditions | 10 |
| Paths | 21 |
| Total Lines | 26 |
| Code Lines | 15 |
| 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 |
||
| 50 | public static function hashCallable(callable $func, string $hashAlgo = 'crc32b'): string |
||
| 51 | { |
||
| 52 | if (\is_object($func)) { |
||
| 53 | return self::generateHashByCallableObject($func, $hashAlgo); |
||
|
|
|||
| 54 | } |
||
| 55 | |||
| 56 | if (\is_string($func) && strpos($func, '::') !== false) { |
||
| 57 | $func = explode('::', $func, 2); |
||
| 58 | } |
||
| 59 | |||
| 60 | if (\is_array($func) && \count($func) === 2) { |
||
| 61 | [$classRef, $method] = $func; |
||
| 62 | $ref = (new \ReflectionClass($classRef))->getMethod($method); |
||
| 63 | } elseif (\is_string($func)) { |
||
| 64 | if (class_exists($func, false)) { |
||
| 65 | $ref = new \ReflectionClass($func); |
||
| 66 | } elseif (\function_exists($func)) { |
||
| 67 | $ref = new \ReflectionFunction($func); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if (!isset($ref)) { |
||
| 72 | throw new \RuntimeException('Could not calculate hash for passed callable.'); |
||
| 73 | } |
||
| 74 | |||
| 75 | return self::generateHashByReflection($ref, $hashAlgo); |
||
| 76 | } |
||
| 162 |