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 |
||
10 | class Pool extends Client |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var array Beginning of the string in the header or value that indicates whether the save value case |
||
15 | */ |
||
16 | public static $safeCaseValues = ['dialstring', 'callerid', 'connectedline']; |
||
17 | /** |
||
18 | * @var array Asterisk Call Manager Interface versions for each session |
||
19 | */ |
||
20 | protected $amiVersions = []; |
||
21 | |||
22 | /** |
||
23 | * Prepares environment scope |
||
24 | * @param string $data Address |
||
25 | * @return array |
||
26 | */ |
||
27 | public static function prepareEnv($data) |
||
37 | |||
38 | /** |
||
39 | * Extract key and value pair from line. |
||
40 | * @param string $line |
||
41 | * @return array |
||
42 | */ |
||
43 | public static function extract($line) |
||
67 | |||
68 | /** |
||
69 | * Sets AMI version |
||
70 | * @param string $addr Address |
||
71 | * @param string $ver Version |
||
72 | * @return void |
||
73 | */ |
||
74 | public function setAmiVersion($addr, $ver) |
||
78 | |||
79 | /** |
||
80 | * Setting default config options |
||
81 | * Overriden from NetworkClient::getConfigDefaults |
||
82 | * @return array |
||
83 | */ |
||
84 | protected function getConfigDefaults() |
||
93 | } |
||
94 |
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.