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 |
||
15 | class WebDriver extends RemoteWebDriver implements LoggerAware |
||
16 | { |
||
17 | const INSTRUCTION_MOUSE_MOVETO = 'mouseMoveTo'; |
||
18 | const INSTRUCTION_MOUSE_CLICK = 'mouseClick'; |
||
19 | |||
20 | const BY_XPATH = 'byXpath'; |
||
21 | const BY_ID = 'byId'; |
||
22 | const BY_CSS_SELECTOR = 'byCssSelector'; |
||
23 | |||
24 | /** |
||
25 | * @var Logger |
||
26 | */ |
||
27 | |||
28 | protected $logger; |
||
29 | |||
30 | |||
31 | public function logFind($by, $selector) |
||
49 | |||
50 | public function logElement(WebDriverElement $element) |
||
68 | |||
69 | public function setRemoteExecuteMethod(LoggingRemoteExecuteMethod $method) |
||
73 | |||
74 | public function setLogger(Logger $logger) |
||
78 | |||
79 | View Code Duplication | public function findElements(WebDriverBy $by) |
|
88 | |||
89 | View Code Duplication | public function findElement(WebDriverBy $by) |
|
96 | |||
97 | public function elementExists($selector, $by = 'byId') |
||
106 | |||
107 | public function elementAttached(WebDriverElement $element) |
||
116 | |||
117 | public function elementDisplayed($selector, $by = 'byId') |
||
126 | |||
127 | /** |
||
128 | * |
||
129 | * @param string $xpath |
||
130 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
131 | */ |
||
132 | |||
133 | public function byXpath($xpath) |
||
137 | |||
138 | /** |
||
139 | * |
||
140 | * @param string $id |
||
141 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
142 | */ |
||
143 | |||
144 | public function byId($id) |
||
148 | |||
149 | /** |
||
150 | * |
||
151 | * @param string $selector |
||
152 | * @return \Facebook\WebDriver\Remote\RemoteWebElement |
||
153 | */ |
||
154 | |||
155 | public function byCssSelector($selector) |
||
159 | |||
160 | public function __destruct() |
||
170 | |||
171 | } |
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.