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 |
||
| 33 | class MinkContext extends BaseMinkContext |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var array a list of window names identified by the name the tester refers to them in the step definitions. |
||
| 37 | * @example ['My tab' => 'WindowNameGivenByBrowser', 'My other tab' => 'WindowNameGivenByBrowser'] |
||
| 38 | */ |
||
| 39 | private $windows = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @Then /^the response should contain \'([^\']*)\'$/ |
||
| 43 | */ |
||
| 44 | public function theResponseShouldContain($string) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @Then /^the response should match xpath \'([^\']*)\'$/ |
||
| 51 | */ |
||
| 52 | public function theResponseShouldMatchXpath($xpath) |
||
|
|
|||
| 53 | { |
||
| 54 | $this->printLastResponse(); die; |
||
| 55 | $document = new DOMDocument(); |
||
| 56 | $document->loadXML($this->getSession()->getPage()->getContent()); |
||
| 57 | |||
| 58 | $xpathObj = new DOMXPath($document); |
||
| 59 | $xpathObj->registerNamespace('ds', XMLSecurityDSig::XMLDSIGNS); |
||
| 60 | $xpathObj->registerNamespace('mdui', Common::NS); |
||
| 61 | $xpathObj->registerNamespace('shibmd', Scope::NS); |
||
| 62 | $nodeList = $xpathObj->query($xpath); |
||
| 63 | |||
| 64 | View Code Duplication | if (!$nodeList || $nodeList->length === 0) { |
|
| 65 | $message = sprintf('The xpath "%s" did not result in at least one match.', $xpath); |
||
| 66 | throw new ExpectationException($message, $this->getSession()); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @Then /^the response should not match xpath \'([^\']*)\'$/ |
||
| 72 | */ |
||
| 73 | public function theResponseShouldNotMatchXpath($xpath) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @Given /^I should see URL "([^"]*)"$/ |
||
| 95 | */ |
||
| 96 | public function iShouldSeeUrl($url) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @Given /^I should not see URL "([^"]*)"$/ |
||
| 103 | */ |
||
| 104 | public function iShouldNotSeeUrl($url) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @Given /^I open (\d+) browser tabs identified by "([^"]*)"$/ |
||
| 111 | */ |
||
| 112 | public function iOpenTwoBrowserTabsIdentifiedBy($numberOfTabs, $tabNames) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @Given /^I switch to "([^"]*)"$/ |
||
| 141 | */ |
||
| 142 | public function iSwitchToWindow($windowName) |
||
| 148 | |||
| 149 | public function switchToWindow($windowName) |
||
| 156 | } |
||
| 157 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.