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 RendererHelperInterface |
||
| 31 | { |
||
| 32 | /** @var ConfigInterface */ |
||
| 33 | private $configuration; |
||
| 34 | /** @var EnvironmentManager */ |
||
| 35 | private $environmentManager; |
||
| 36 | /** @var AclAdapterInterface */ |
||
| 37 | private $aclAdapter; |
||
| 38 | /** @var AuthAdapterInterface */ |
||
| 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 | * IsAllowedHelper constructor. |
||
| 80 | * |
||
| 81 | * @param ConfigInterface $configuration |
||
| 82 | * @param EnvironmentManager $environmentManager |
||
| 83 | * @param AclAdapterInterface $aclAdapter |
||
| 84 | * @param AuthAdapterInterface $authAdapter |
||
| 85 | * @param ResourceStorage $resourceStorage |
||
| 86 | * @param ApplicationStorage $applicationStorage |
||
| 87 | */ |
||
| 88 | 3 | View Code Duplication | public function __construct( |
| 103 | |||
| 104 | /** |
||
| 105 | * A renderer helper should be called with its name. |
||
| 106 | * |
||
| 107 | * @return bool |
||
| 108 | */ |
||
| 109 | 3 | public function __invoke() : bool |
|
| 136 | |||
| 137 | /** |
||
| 138 | * Matches the given resource name against router URLs and if found, changes it to the assigned middleware name. |
||
| 139 | * @TODO: make sure it is NOT possible to give a custom resource with a name that can match against a router path. |
||
| 140 | * |
||
| 141 | * @param string $resourceName |
||
| 142 | * @param string $applicationName |
||
| 143 | */ |
||
| 144 | 2 | private function checkResourceNameAgainstRouting(string &$resourceName, string $applicationName) : void |
|
| 162 | } |
||
| 163 |
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.