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 HTML implements EventSubscriberInterface |
||
| 13 | { |
||
| 14 | const |
||
| 15 | DEFAULT_REPORT_FILENAME = 'report.html'; |
||
| 16 | |||
| 17 | private |
||
| 18 | $defects, |
||
| 19 | $reporter, |
||
| 20 | $reportFilename, |
||
| 21 | $currentFile; |
||
| 22 | |||
| 23 | public function __construct(HTMLReporter $reporter) |
||
| 30 | |||
| 31 | public function setReportFilename($filename) |
||
| 37 | |||
| 38 | View Code Duplication | public static function getSubscribedEvents() |
|
| 46 | |||
| 47 | public function setCurrentFile(ChangeFile $event) |
||
| 53 | |||
| 54 | public function onDefect(Defect $event) |
||
| 64 | |||
| 65 | private function formatMessage($message) |
||
| 73 | |||
| 74 | public function postMortemReport(TraverseEnd $event) |
||
| 80 | } |
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.