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 |
||
| 24 | View Code Duplication | class ActivateOperation extends Operation |
|
| 25 | { |
||
| 26 | /** |
||
| 27 | * @inheritdoc |
||
| 28 | */ |
||
| 29 | protected function get_controls() |
||
| 30 | { |
||
| 31 | return [ |
||
| 32 | |||
| 33 | self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER, |
||
| 34 | self::CONTROL_RECORD => true, |
||
| 35 | self::CONTROL_OWNERSHIP => true |
||
| 36 | |||
| 37 | ] + parent::get_controls(); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @inheritdoc |
||
| 42 | */ |
||
| 43 | protected function validate(ErrorCollection $errors) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @inheritdoc |
||
| 50 | */ |
||
| 51 | protected function process() |
||
| 65 | } |
||
| 66 |