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 |
||
32 | abstract class ProjectAwareCommand extends Command { |
||
33 | /** |
||
34 | * Logger. |
||
35 | * |
||
36 | * @var \Psr\Log\LoggerInterface |
||
37 | */ |
||
38 | protected $logger; |
||
39 | |||
40 | /** |
||
41 | * Moodle bridge. |
||
42 | * |
||
43 | * @var \ComponentManager\Moodle |
||
44 | */ |
||
45 | protected $moodle; |
||
46 | |||
47 | /** |
||
48 | * Package format factory. |
||
49 | * |
||
50 | * @var \ComponentManager\PackageFormat\PackageFormatFactory |
||
51 | */ |
||
52 | protected $packageFormatFactory; |
||
53 | |||
54 | /** |
||
55 | * Package repository factory. |
||
56 | * |
||
57 | * @var \ComponentManager\PackageRepository\PackageRepositoryFactory |
||
58 | */ |
||
59 | protected $packageRepositoryFactory; |
||
60 | |||
61 | /** |
||
62 | * Package source factory. |
||
63 | * |
||
64 | * @var \ComponentManager\PackageSource\PackageSourceFactory |
||
65 | */ |
||
66 | protected $packageSourceFactory; |
||
67 | |||
68 | /** |
||
69 | * Project. |
||
70 | * |
||
71 | * Lazily loaded -- be sure to call getProject() in order to ensure the |
||
72 | * value is defined. |
||
73 | * |
||
74 | * @var \ComponentManager\Project\Project |
||
75 | */ |
||
76 | protected $project; |
||
77 | |||
78 | /** |
||
79 | * Initialiser. |
||
80 | * |
||
81 | * @param \ComponentManager\PackageFormat\PackageFormatFactory $packageFormatFactory |
||
|
|||
82 | * @param \ComponentManager\PackageRepository\PackageRepositoryFactory $packageRepositoryFactory |
||
83 | * @param \ComponentManager\PackageSource\PackageSourceFactory $packageSourceFactory |
||
84 | * @param \Psr\Log\LoggerInterface $logger |
||
85 | */ |
||
86 | View Code Duplication | public function __construct(PackageRepositoryFactory $packageRepositoryFactory, |
|
98 | |||
99 | /** |
||
100 | * Get the Moodle bridge. |
||
101 | * |
||
102 | * @param string|null $moodleDirectory |
||
103 | * |
||
104 | * @return \ComponentManager\Moodle |
||
105 | */ |
||
106 | protected function getMoodle($moodleDirectory=null) { |
||
116 | |||
117 | /** |
||
118 | * Get project. |
||
119 | * |
||
120 | * @param string|null $projectFilename |
||
121 | * @param string|null $projectLockFilename |
||
122 | * |
||
123 | * @return \ComponentManager\Project\Project |
||
124 | */ |
||
125 | protected function getProject($projectFilename=null, $projectLockFilename=null) { |
||
157 | } |
||
158 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.