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 |
||
26 | class ViewFinder extends AbstractFinder |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * Find a result based on a specific criteria. |
||
31 | * |
||
32 | * @since 0.1.0 |
||
33 | * |
||
34 | * @param array $criteria Criteria to search for. |
||
35 | * @param EngineInterface $engine Optional. Engine to use with the view. |
||
|
|||
36 | * |
||
37 | * @return ViewInterface View that was found. |
||
1 ignored issue
–
show
|
|||
38 | */ |
||
39 | 17 | public function find(array $criteria, EngineInterface $engine = null) |
|
55 | |||
56 | /** |
||
57 | * Initialize the views that can be iterated. |
||
58 | * |
||
59 | * @since 0.1.0 |
||
60 | * |
||
61 | * @param string $uri URI to use for the view. |
||
62 | * @param EngineInterface $engine Optional. Engine to use with the view. |
||
63 | */ |
||
64 | 17 | protected function initializeViews($uri, EngineInterface $engine = null) |
|
70 | |||
71 | /** |
||
72 | * Initialize a single view by instantiating class name strings and calling closures. |
||
73 | * |
||
74 | * @since 0.1.0 |
||
75 | * |
||
76 | * @param mixed $view View to instantiate. |
||
77 | * @param string $uri URI to use for the view. |
||
78 | * @param EngineInterface $engine Optional. Engine to use with the view. |
||
79 | * |
||
80 | * @return ViewInterface Instantiated view. |
||
81 | * @throws FailedToInstantiateViewException If the view could not be instantiated. |
||
82 | */ |
||
83 | 17 | View Code Duplication | protected function initializeView($view, $uri, EngineInterface $engine = null) |
104 | |||
105 | /** |
||
106 | * Get the config key for the Findables definitions. |
||
107 | * |
||
108 | * @since 0.1.0 |
||
109 | * |
||
110 | * @return string Config key use to define the Findables. |
||
111 | */ |
||
112 | 7 | protected function getFindablesConfigKey() |
|
116 | } |
||
117 |
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.