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 | final class ServiceServiceProvider extends AbstractServiceProvider |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $config; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @api |
||
| 21 | * |
||
| 22 | * @param ServiceConfig $config |
||
| 23 | */ |
||
| 24 | public function __construct(ServiceConfig $config) |
||
| 29 | |||
| 30 | public function register() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param ServiceDefinition $definition |
||
| 39 | * |
||
| 40 | * @throws NotClassDefinitionException |
||
| 41 | * |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | private function registerService(ServiceDefinition $definition) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param ClassDefinition $service |
||
| 81 | * @param ServiceDefinition $definition |
||
| 82 | */ |
||
| 83 | private function addMethodCalls(ClassDefinition $service, ServiceDefinition $definition) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param ServiceDefinition $definition |
||
| 92 | * |
||
| 93 | * @return \Closure |
||
| 94 | */ |
||
| 95 | private function createAliasFactory(ServiceDefinition $definition) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param ServiceDefinition $definition |
||
| 104 | * |
||
| 105 | * @return \Closure |
||
| 106 | */ |
||
| 107 | View Code Duplication | private function createFactoryFactory(ServiceDefinition $definition) |
|
| 116 | |||
| 117 | /** |
||
| 118 | * @param array $arguments |
||
| 119 | * |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | private function injectContainer(array $arguments) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param array $arguments |
||
| 136 | * |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | private function resolveArguments(array $arguments) |
||
| 156 | } |
||
| 157 |
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..