| Conditions | 13 |
| Paths | 14 |
| Total Lines | 38 |
| Lines | 18 |
| Ratio | 47.37 % |
| 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 |
||
| 46 | public static function find($class, $namespace = null, $rootns = null) |
||
| 47 | { |
||
| 48 | $e = explode('\\', $class); |
||
| 49 | if ($e[0] === '') { |
||
| 50 | return $class; |
||
| 51 | } |
||
| 52 | if ('Pool' === $class || 'TransportContext' === $class) { |
||
| 53 | return '\\PHPDaemon\\Core\\' . $class; |
||
| 54 | } |
||
| 55 | if (mb_orig_strpos($class, '\\') === false && $namespace === null) { |
||
| 56 | if ('Example' === substr($class, 0, 7)) { |
||
| 57 | array_unshift($e, 'Examples'); |
||
| 58 | } |
||
| 59 | View Code Duplication | if ('Server' === substr($class, -6)) { |
|
| 60 | $path = '\\PHPDaemon\\Servers\\' . substr($class, 0, -6) . '\\Pool'; |
||
| 61 | $r = str_replace('\\Servers\\Servers', '\\Servers', $path); |
||
| 62 | Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.'); |
||
| 63 | return $r; |
||
| 64 | } |
||
| 65 | View Code Duplication | if ('Client' === substr($class, -6)) { |
|
| 66 | $path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -6) . '\\Pool'; |
||
| 67 | $r = str_replace('\\Clients\\Clients', '\\Clients', $path); |
||
| 68 | Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.'); |
||
| 69 | return $r; |
||
| 70 | } |
||
| 71 | View Code Duplication | if ('ClientAsync' === substr($class, -11)) { |
|
| 72 | $path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -11) . '\\Pool'; |
||
| 73 | $r = str_replace('\\Client\\Clients', '\\Clients', $path); |
||
| 74 | Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.'); |
||
| 75 | return $r; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | if ($namespace !== null && sizeof($e) < 2) { |
||
| 79 | array_unshift($e, $namespace); |
||
| 80 | } |
||
| 81 | array_unshift($e, '\\' . ($rootns !== null ? $rootns : Daemon::$config->defaultns->value)); |
||
| 82 | return implode('\\', $e); |
||
| 83 | } |
||
| 84 | } |
||
| 85 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.