| Conditions | 16 |
| Paths | 84 |
| Total Lines | 66 |
| Code Lines | 49 |
| Lines | 14 |
| Ratio | 21.21 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 49 | public function navigateTo(array $instructions) |
||
| 50 | { |
||
| 51 | $this->testCase->assertGreaterThan(0, count($instructions), 'Instruction navigator requires at least one instruction'); |
||
| 52 | $useAutomaticTiming = true; |
||
| 53 | foreach ($instructions as $key => $instruction) { |
||
| 54 | if (count($instruction) > 0 && $instruction[0] == self::INSTRUCTION_USE_MANUAL_TIMING) { |
||
| 55 | $useAutomaticTiming = false; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | foreach ($instructions as $instruction) { |
||
| 60 | $this->testCase->assertCount(2, $instruction, 'Navigation instructions need to be a 2 member array. First item is the instruction type, the second is the XPath'); |
||
| 61 | list($instruction, $xpath) = $instruction; |
||
| 62 | if ($useAutomaticTiming) { |
||
| 63 | $this->testCase->sleep('100ms'); // Courtesy sleep of 100ms |
||
| 64 | if ($instruction == self::INSTRUCTION_MOUSE_MOVETO || $instruction == self::INSTRUCTION_MOUSE_CLICK) { |
||
| 65 | $this->webdriver->wait()->until(ExpectedCondition::elementExists($xpath, WebDriver::BY_XPATH)); |
||
|
|
|||
| 66 | $this->webdriver->wait(5)->until(ExpectedCondition::elementToBeClickable(WebDriverBy::xpath($xpath))); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | switch ($instruction) { |
||
| 71 | case self::INSTRUCTION_MOUSE_CLICK: |
||
| 72 | $element = $this->webdriver->byXpath($xpath); |
||
| 73 | if (!$element->isDisplayed()) { |
||
| 74 | throw new ElementNotVisibleException('The element is not visible: '.$xpath); |
||
| 75 | } |
||
| 76 | $element->click(); |
||
| 77 | break; |
||
| 78 | case self::INSTRUCTION_MOUSE_MOVETO: |
||
| 79 | $element = $this->webdriver->byXpath($xpath); |
||
| 80 | $this->webdriver->getMouse()->mouseMove($element->getCoordinates()); |
||
| 81 | break; |
||
| 82 | case self::INSTRUCTION_WAIT_FOR_EXISTS: |
||
| 83 | $this->webdriver->wait()->until(ExpectedCondition::elementExists($xpath, WebDriver::BY_XPATH)); |
||
| 84 | break; |
||
| 85 | case self::INSTRUCTION_WAIT_FOR_NOT_EXISTS: |
||
| 86 | $this->webdriver->wait()->until( |
||
| 87 | ExpectedCondition::not( |
||
| 88 | ExpectedCondition::elementExists($xpath, WebDriver::BY_XPATH) |
||
| 89 | ) |
||
| 90 | ); |
||
| 91 | break; |
||
| 92 | View Code Duplication | case self::INSTRUCTION_WAIT_FOR_DISPLAYED: |
|
| 93 | $element = $this->webdriver->byXpath($xpath); |
||
| 94 | $this->webdriver->wait()->until(ExpectedCondition::visibilityOf($element)); |
||
| 95 | break; |
||
| 96 | case self::INSTRUCTION_PAUSE: |
||
| 97 | $this->testCase->sleep($xpath); |
||
| 98 | break; |
||
| 99 | View Code Duplication | case self::INSTRUCTION_WAIT_FOR_HIDDEN: |
|
| 100 | $element = $this->webdriver->byXpath($xpath); |
||
| 101 | $this->webdriver->wait()->until( |
||
| 102 | ExpectedCondition::not( |
||
| 103 | ExpectedCondition::visibilityOf( |
||
| 104 | $element |
||
| 105 | ) |
||
| 106 | ) |
||
| 107 | ); |
||
| 108 | break; |
||
| 109 | default: |
||
| 110 | throw new InvalidConfigurationException('Unknown login instruction: '.$instruction); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | } |
||
| 115 | |||
| 117 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: