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 |
||
| 7 | View Code Duplication | class Catch_ extends Node\Stmt |
|
|
|
|||
| 8 | { |
||
| 9 | /** @var Node\Name Class of exception */ |
||
| 10 | public $type; |
||
| 11 | /** @var string Variable for exception */ |
||
| 12 | public $var; |
||
| 13 | /** @var Node[] Statements */ |
||
| 14 | public $stmts; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Constructs a catch node. |
||
| 18 | * |
||
| 19 | * @param Node\Name $type Class of exception |
||
| 20 | * @param string $var Variable for exception |
||
| 21 | * @param Node[] $stmts Statements |
||
| 22 | * @param array $attributes Additional attributes |
||
| 23 | */ |
||
| 24 | public function __construct(Node\Name $type, $var, array $stmts = array(), array $attributes = array()) { |
||
| 25 | parent::__construct($attributes); |
||
| 26 | $this->type = $type; |
||
| 27 | $this->var = $var; |
||
| 28 | $this->stmts = $stmts; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function getSubNodeNames() { |
||
| 34 | } |
||
| 35 |
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.