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 |
||
| 26 | class RouteMatchSpecificationManager |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var CollectionInterface[]|RouteMatchSpecificationInterface[] $specifications |
||
| 30 | */ |
||
| 31 | private $specifications; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var RouteMatchSpecificationFactory $specifications_factory |
||
| 35 | */ |
||
| 36 | private $specifications_factory; |
||
| 37 | |||
| 38 | |||
| 39 | /** |
||
| 40 | * RouteMatchSpecificationManager constructor. |
||
| 41 | * |
||
| 42 | * @param RouteMatchSpecificationCollection $specifications |
||
| 43 | * @param RouteMatchSpecificationFactory $specifications_factory |
||
| 44 | */ |
||
| 45 | public function __construct( |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * Perform any early setup required for block editors to functions |
||
| 57 | * |
||
| 58 | * @return void |
||
| 59 | * @throws CollectionLoaderException |
||
| 60 | * @throws CollectionDetailsException |
||
| 61 | */ |
||
| 62 | public function initialize() |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * @return CollectionInterface|\EventEspresso\core\domain\entities\routing\specifications\RouteMatchSpecificationInterface[] |
||
| 70 | * @throws CollectionLoaderException |
||
| 71 | * @throws CollectionDetailsException |
||
| 72 | * @since 4.9.71.p |
||
| 73 | */ |
||
| 74 | View Code Duplication | private function populateSpecificationCollection() |
|
| 104 | |||
| 105 | |||
| 106 | /** |
||
| 107 | * Given the FQCN for a RouteMatchSpecification, will return true if the current request matches |
||
| 108 | * |
||
| 109 | * @param string $routeMatchSpecificationFqcn fully qualified class name |
||
| 110 | * @return bool |
||
| 111 | * @throws InvalidClassException |
||
| 112 | * @since 4.9.71.p |
||
| 113 | */ |
||
| 114 | public function routeMatchesCurrentRequest($routeMatchSpecificationFqcn) |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * Handy method for development that returns |
||
| 127 | * a list of existing RouteMatchSpecification classes |
||
| 128 | * matching the current request that can be used to identify it. |
||
| 129 | * If no matches are returned (or nothing acceptable) |
||
| 130 | * then create a new one that better matches your requirements. |
||
| 131 | * |
||
| 132 | * @return array |
||
| 133 | * @since 4.9.71.p |
||
| 134 | */ |
||
| 135 | public function findRouteMatchSpecificationsMatchingCurrentRequest() |
||
| 146 | } |
||
| 147 |