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