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 |
||
15 | final class ServiceServiceProvider extends AbstractServiceProvider |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $config; |
||
21 | |||
22 | /** |
||
23 | * @param ServiceConfig $config |
||
24 | */ |
||
25 | public function __construct(ServiceConfig $config) |
||
30 | |||
31 | public function register() |
||
37 | |||
38 | /** |
||
39 | * @param ServiceDefinition $definition |
||
40 | * |
||
41 | * @throws NotClassDefinitionException |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | private function registerService(ServiceDefinition $definition) |
||
79 | |||
80 | /** |
||
81 | * @param ClassDefinition $service |
||
82 | * @param ServiceDefinition $definition |
||
83 | */ |
||
84 | private function addMethodCalls(ClassDefinition $service, ServiceDefinition $definition) |
||
90 | |||
91 | /** |
||
92 | * @param ServiceDefinition $definition |
||
93 | * |
||
94 | * @return \Closure |
||
95 | */ |
||
96 | private function createAliasFactory(ServiceDefinition $definition) |
||
102 | |||
103 | /** |
||
104 | * @param ServiceDefinition $definition |
||
105 | * |
||
106 | * @return \Closure |
||
107 | */ |
||
108 | View Code Duplication | private function createFactoryFactory(ServiceDefinition $definition) |
|
117 | |||
118 | /** |
||
119 | * @param array $arguments |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | private function injectContainer(array $arguments) |
||
134 | |||
135 | /** |
||
136 | * @param array $arguments |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | private function resolveArguments(array $arguments) |
||
157 | } |
||
158 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..