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 |
||
| 8 | View Code Duplication | class GroupUse extends Stmt |
|
|
|
|||
| 9 | { |
||
| 10 | /** @var int Type of group use */ |
||
| 11 | public $type; |
||
| 12 | /** @var Name Prefix for uses */ |
||
| 13 | public $prefix; |
||
| 14 | /** @var UseUse[] Uses */ |
||
| 15 | public $uses; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Constructs a group use node. |
||
| 19 | * |
||
| 20 | * @param Name $prefix Prefix for uses |
||
| 21 | * @param UseUse[] $uses Uses |
||
| 22 | * @param int $type Type of group use |
||
| 23 | * @param array $attributes Additional attributes |
||
| 24 | */ |
||
| 25 | public function __construct(Name $prefix, array $uses, $type = Use_::TYPE_NORMAL, array $attributes = array()) { |
||
| 26 | parent::__construct($attributes); |
||
| 27 | $this->type = $type; |
||
| 28 | $this->prefix = $prefix; |
||
| 29 | $this->uses = $uses; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function getSubNodeNames() { |
||
| 35 | } |
||
| 36 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.