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 |
||
9 | View Code Duplication | class PlatformSpecificExemplifyRunner implements ExemplifyRunner |
|
|
|||
10 | { |
||
11 | const COMMAND_NAME = 'exemplify'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $phpspecPath; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $phpspecConfig; |
||
22 | |||
23 | /** |
||
24 | * @var CommandRunner |
||
25 | */ |
||
26 | private $commandRunner; |
||
27 | |||
28 | /** |
||
29 | * @var CachingExecutableFinder |
||
30 | */ |
||
31 | private $executableFinder; |
||
32 | |||
33 | /** |
||
34 | * @param CommandRunner $commandRunner |
||
35 | * @param CachingExecutableFinder $executableFinder |
||
36 | * @param string $phpspecPath |
||
37 | */ |
||
38 | public function __construct( |
||
49 | |||
50 | /** |
||
51 | * @return boolean |
||
52 | */ |
||
53 | public function isSupported() |
||
57 | |||
58 | public function runExemplifyCommand($className, $methodName) |
||
65 | |||
66 | /** |
||
67 | * @param $className |
||
68 | * @param $methodName |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | private function getCommandArguments($className, $methodName) |
||
80 | |||
81 | /** |
||
82 | * @return array |
||
83 | */ |
||
84 | private function composeConfigOption() |
||
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.