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 |
||
| 24 | class DefinedHelper implements RendererHelperInterface |
||
| 25 | { |
||
| 26 | /** @var string */ |
||
| 27 | private $templateViewPath; |
||
| 28 | /** @var string */ |
||
| 29 | private $defaultTemplateViewPath; |
||
| 30 | |||
| 31 | use ThemeCheckTrait; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Should return the name of the helper. |
||
| 35 | * |
||
| 36 | * @return string |
||
| 37 | * @codeCoverageIgnore - plain text |
||
| 38 | */ |
||
| 39 | public static function getName() : string |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Should return the name of the helper. |
||
| 46 | * |
||
| 47 | * @return string |
||
| 48 | * @codeCoverageIgnore - plain text |
||
| 49 | */ |
||
| 50 | public static function getDefinition() : string |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Should return a description text. |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | * @codeCoverageIgnore - plain text |
||
| 60 | */ |
||
| 61 | public static function getDescription() : string |
||
| 66 | |||
| 67 | /** |
||
| 68 | * DefinedHelper constructor. |
||
| 69 | * |
||
| 70 | * @param ConfigInterface $configuration |
||
| 71 | * @param EnvironmentManager $environmentManager |
||
| 72 | */ |
||
| 73 | public function __construct(ConfigInterface $configuration, EnvironmentManager $environmentManager) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * A renderer helper should be called with its name. |
||
| 94 | * |
||
| 95 | * @return bool |
||
| 96 | */ |
||
| 97 | public function __invoke() : bool |
||
| 112 | } |
||
| 113 |
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.