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 |
||
| 23 | class CapabilityApi implements CapabilityApiInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var ExtensionRepository |
||
| 27 | */ |
||
| 28 | private $extensionRepository; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var ExtensionEntity[] |
||
| 32 | */ |
||
| 33 | private $extensionsByCapability = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var ExtensionEntity[] |
||
| 37 | */ |
||
| 38 | private $extensionsByName = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Capability constructor. |
||
| 42 | * @param ExtensionRepositoryInterface $extensionRepository |
||
| 43 | */ |
||
| 44 | public function __construct(ExtensionRepositoryInterface $extensionRepository) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Load extensions into private property cache. |
||
| 51 | */ |
||
| 52 | private function load() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | public function getExtensionsCapableOf($capability) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | public function isCapable($extensionName, $requestedCapability) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritdoc} |
||
| 93 | */ |
||
| 94 | public function getCapabilitiesOf($extensionName) |
||
| 102 | } |
||
| 103 |