Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
12 | class ClassFinder |
||
13 | { |
||
14 | use \PHPDaemon\Traits\ClassWatchdog; |
||
15 | use \PHPDaemon\Traits\StaticObjectWatchdog; |
||
16 | |||
17 | /** |
||
18 | * Get base class name of the given class or object |
||
19 | * @param string|object $class Object or String |
||
20 | * @return string Class |
||
21 | */ |
||
22 | public static function getClassBasename($class) |
||
30 | |||
31 | /** |
||
32 | * @param string $class |
||
33 | */ |
||
34 | public static function getNamespace(string $class): string |
||
38 | |||
39 | /** |
||
40 | * Find class |
||
41 | * @param string $class Class |
||
42 | * @param string $namespace Namespace |
||
|
|||
43 | * @param string $rootns Root namespace |
||
44 | * @return string |
||
45 | */ |
||
46 | public static function find($class, $namespace = null, $rootns = null) |
||
84 | } |
||
85 |
This check looks for
@param
annotations 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.