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 |
||
15 | class ContentItem extends PermalinkFrontMatterDocument implements CollectableItem, TemplateReadyDocument |
||
16 | { |
||
17 | use CollectableItemTrait; |
||
18 | use TemplateEngineDependent; |
||
19 | |||
20 | /** @var MarkupEngine */ |
||
21 | private $markupEngine; |
||
22 | |||
23 | 57 | public function __construct(File $file) |
|
29 | |||
30 | public function setMarkupEngine(MarkupEngineManager $manager) |
||
35 | |||
36 | /// |
||
37 | // Permalink management |
||
38 | /// |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function handleSpecialRedirects() |
||
59 | |||
60 | /// |
||
61 | // Document body transformation |
||
62 | /// |
||
63 | |||
64 | /** |
||
65 | * @throws TemplateErrorInterface |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 5 | public function getContent() |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | 6 | View Code Duplication | public function createJail() |
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | View Code Duplication | public function jsonSerialize() |
|
109 | } |
||
110 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.