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 |
||
| 30 | class IsAllowedHelper implements HelperInterface |
||
| 31 | { |
||
| 32 | /** @var ConfigurationInterface */ |
||
| 33 | private $configuration; |
||
| 34 | /** @var EnvironmentInterface */ |
||
| 35 | private $environmentManager; |
||
| 36 | /** @var AclInterface */ |
||
| 37 | private $aclAdapter; |
||
| 38 | /** @var AuthInterface */ |
||
| 39 | private $authAdapter; |
||
| 40 | /** @var ResourceStorage */ |
||
| 41 | private $resourceStorage; |
||
| 42 | /** @var ApplicationStorage */ |
||
| 43 | private $applicationStorage; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Should return the name of the helper. |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | * @codeCoverageIgnore - plain text |
||
| 50 | */ |
||
| 51 | public static function getName() : string |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Should return the name of the helper. |
||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | * @codeCoverageIgnore - plain text |
||
| 61 | */ |
||
| 62 | public static function getDefinition() : string |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Should return a description text. |
||
| 69 | * |
||
| 70 | * @return string |
||
| 71 | * @codeCoverageIgnore - plain text |
||
| 72 | */ |
||
| 73 | public static function getDescription() : string |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Gets helper options for the render. |
||
| 80 | * |
||
| 81 | * @return array |
||
| 82 | * @codeCoverageIgnore - empty array |
||
| 83 | */ |
||
| 84 | public static function getOptions() : array |
||
| 88 | |||
| 89 | /** |
||
| 90 | * IsAllowedHelper constructor. |
||
| 91 | * |
||
| 92 | * @param ConfigurationInterface $configuration |
||
| 93 | * @param EnvironmentInterface $environmentManager |
||
| 94 | * @param AclInterface $aclAdapter |
||
| 95 | * @param AuthInterface $authAdapter |
||
| 96 | * @param ResourceStorage $resourceStorage |
||
| 97 | * @param ApplicationStorage $applicationStorage |
||
| 98 | */ |
||
| 99 | 3 | View Code Duplication | public function __construct( |
| 114 | |||
| 115 | /** |
||
| 116 | * A renderer helper should be called with its name. |
||
| 117 | * |
||
| 118 | * @return bool |
||
| 119 | */ |
||
| 120 | 3 | public function __invoke() : bool |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Matches the given resource name against router URLs and if found, changes it to the assigned middleware name. |
||
| 150 | * @TODO: make sure it is NOT possible to give a custom resource with a name that can match against a router path. |
||
| 151 | * |
||
| 152 | * @param string $resourceName |
||
| 153 | * @param string $applicationName |
||
| 154 | */ |
||
| 155 | 2 | private function checkResourceNameAgainstRouting(string&$resourceName, string $applicationName) : void |
|
| 172 | } |
||
| 173 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.