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 |
||
| 10 | class StopExtension |
||
| 11 | { |
||
| 12 | private $stopStrategies = array(); |
||
| 13 | |||
| 14 | public function init(Configuration $_configuration, Dispatcher $_eventDispatcher) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @Event("Scanner.Scan.isStopped") |
||
| 28 | */ |
||
| 29 | public function isStopped(Event $event) |
||
| 30 | { |
||
| 31 | foreach ($this->stopStrategies as $strategy) { |
||
| 32 | if ($strategy->isStopped()) { |
||
| 33 | $event->setProcessed(); |
||
| 34 | |||
| 35 | return true; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | View Code Duplication | public function getStrategy($name) |
|
| 50 | } |
||
| 51 |