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 | class ReflectionClass |
||
| 16 | { |
||
| 17 | private $class; |
||
| 18 | private $properties; |
||
| 19 | private $injectionStrategies; |
||
| 20 | private $instanciator; |
||
| 21 | |||
| 22 | 5 | public function __construct( |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Add a property to be injected in the new object |
||
| 36 | * |
||
| 37 | * @param string $property |
||
| 38 | * @param mixed $value |
||
| 39 | * |
||
| 40 | * @return self |
||
| 41 | */ |
||
| 42 | 2 | public function withProperty(string $property, $value): self |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Add a set of properties that need to be injected |
||
| 54 | * |
||
| 55 | * @param array $properties |
||
| 56 | * |
||
| 57 | * @return self |
||
| 58 | */ |
||
| 59 | 1 | public function withProperties(array $properties): self |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Return the collection of properties that will be injected in the object |
||
| 71 | * |
||
| 72 | * @return CollectionInterface |
||
| 73 | */ |
||
| 74 | 1 | public function getProperties(): CollectionInterface |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Return the list of injection strategies used |
||
| 81 | * |
||
| 82 | * @return TypedCollectionInterface |
||
| 83 | */ |
||
| 84 | 1 | public function getInjectionStrategies(): TypedCollectionInterface |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Return the object instanciator |
||
| 91 | * |
||
| 92 | * @return InstanciatorInterface |
||
| 93 | */ |
||
| 94 | 1 | public function getInstanciator(): InstanciatorInterface |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Return a new instance of the class |
||
| 101 | * |
||
| 102 | * @return object |
||
| 103 | */ |
||
| 104 | 2 | public function buildObject() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @param TypedCollectionInterface $strategies |
||
| 126 | * |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | 5 | View Code Duplication | private function initInjectionStrategies(TypedCollectionInterface $strategies = null) |
| 146 | } |
||
| 147 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.