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 |
||
6 | class GenericMethodAction extends MethodAction { |
||
7 | |||
8 | /** @var GenericAction */ |
||
9 | private $generic; |
||
10 | |||
11 | /** |
||
12 | * @param object $object |
||
13 | * @param string $method |
||
14 | * @param TypeFactory $types |
||
15 | * @param CommentParser $parser |
||
16 | */ |
||
17 | View Code Duplication | public function __construct($object, $method, TypeFactory $types, CommentParser $parser) { |
|
31 | |||
32 | public function generic() { |
||
35 | |||
36 | public function execute(array $parameters) { |
||
39 | |||
40 | public function caption() { |
||
43 | |||
44 | public function description() { |
||
47 | |||
48 | public function fill(array $parameters) { |
||
51 | |||
52 | public function parameters() { |
||
55 | } |
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.