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 | private $afterExecute; |
||
9 | private $caption; |
||
10 | private $fill; |
||
11 | private $description; |
||
12 | private $paramMap = []; |
||
13 | |||
14 | /** |
||
15 | * @param callable $callback Filter for return value of execute() |
||
16 | * @return static |
||
17 | */ |
||
18 | public function setAfterExecute(callable $callback) { |
||
22 | |||
23 | public function execute(array $parameters) { |
||
30 | |||
31 | public function setCaption($caption) { |
||
35 | |||
36 | public function caption() { |
||
39 | |||
40 | public function setDescription($description) { |
||
44 | |||
45 | public function description() { |
||
48 | |||
49 | public function setFill(callable $callback) { |
||
53 | |||
54 | View Code Duplication | public function fill(array $parameters) { |
|
61 | |||
62 | /** |
||
63 | * @param string $name |
||
64 | * @param callable $map Receives Parameter and returns Parameter |
||
65 | * @return static |
||
66 | */ |
||
67 | public function mapParameter($name, callable $map) { |
||
71 | |||
72 | /** |
||
73 | * @return \rtens\domin\Parameter[] |
||
74 | * @throws \Exception |
||
75 | */ |
||
76 | View Code Duplication | public function parameters() { |
|
84 | } |
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.