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 |
||
12 | class Console implements EventSubscriberInterface |
||
13 | { |
||
14 | private |
||
15 | $counter, |
||
16 | $currentFile, |
||
17 | $output; |
||
18 | |||
19 | View Code Duplication | public static function getSubscribedEvents() |
|
27 | |||
28 | public function __construct() |
||
34 | |||
35 | public function setOutput(OutputInterface $output) |
||
41 | |||
42 | public function setCurrentFile(ChangeFile $event) |
||
48 | |||
49 | public function onDefect(Defect $event) |
||
60 | |||
61 | private function formatMessage($message) |
||
69 | |||
70 | public function postMortemReport(TraverseEnd $event) |
||
78 | } |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.