| Conditions | 7 |
| Paths | 36 |
| Total Lines | 63 |
| Code Lines | 41 |
| Lines | 26 |
| Ratio | 41.27 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 67 | public function extract() |
||
| 68 | { |
||
| 69 | $productIterator = new ProductIterator(); |
||
| 70 | $this->values[self::VALUE_PRODUCTS] = $productIterator; |
||
| 71 | $count = 1; |
||
| 72 | |||
| 73 | $testProductXpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath($count); |
||
| 74 | $this->webDriver->wait()->until(ExpectedCondition::elementExists($testProductXpath, WebDriver::BY_XPATH)); |
||
|
|
|||
| 75 | |||
| 76 | while ($this->webDriver->elementExists($testProductXpath, WebDriver::BY_XPATH)) { |
||
| 77 | |||
| 78 | $xpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath($count); |
||
| 79 | $nameElement = $this->webDriver->byXpath($xpath); |
||
| 80 | $name = trim($nameElement->getText()); |
||
| 81 | |||
| 82 | $xpath = $this->theme->getCartSummaryCheckoutProductLoopPriceXpath($count); |
||
| 83 | View Code Duplication | if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
|
| 84 | $priceElement = $this->webDriver->byXpath($xpath); |
||
| 85 | $price = trim($priceElement->getText()); // We do not extract the number value so currency checks can be done |
||
| 86 | } else { |
||
| 87 | $price = 0; |
||
| 88 | } |
||
| 89 | |||
| 90 | $xpath = $this->theme->getCartSummaryCheckoutProductLoopQtyXpath($count); |
||
| 91 | View Code Duplication | if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
|
| 92 | $qtyElement = $this->webDriver->byXpath($xpath); |
||
| 93 | $qty = trim($qtyElement->getText()); |
||
| 94 | } else { |
||
| 95 | $qty = 0; |
||
| 96 | } |
||
| 97 | |||
| 98 | $xpath = $this->theme->getCartSummaryCheckoutProductLoopSubtotalXpath($count); |
||
| 99 | View Code Duplication | if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
|
| 100 | $subtotalElement = $this->webDriver->byXpath($xpath); |
||
| 101 | $subtotal = trim($subtotalElement->getText()); |
||
| 102 | } else { |
||
| 103 | $subtotal = 0; |
||
| 104 | } |
||
| 105 | |||
| 106 | $product = new Product($name, $qty, $price, $subtotal); |
||
| 107 | $productIterator->addProduct($product); |
||
| 108 | $testProductXpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath(++$count); |
||
| 109 | } |
||
| 110 | |||
| 111 | // Tax and shipping may not be displayed |
||
| 112 | |||
| 113 | View Code Duplication | if ($this->webDriver->elementDisplayed($this->theme->getCartSummaryCheckoutTax(), WebDriver::BY_XPATH)) { |
|
| 114 | $this->values[self::VALUE_TAX] |
||
| 115 | = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutTax())->getText()); |
||
| 116 | } |
||
| 117 | View Code Duplication | if ($this->webDriver->elementDisplayed($this->theme->getCartSummaryCheckoutShippingTotal(), WebDriver::BY_XPATH)) { |
|
| 118 | $this->values[self::VALUE_SnH] |
||
| 119 | = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutShippingTotal())->getText()); |
||
| 120 | } |
||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | $this->values[self::VALUE_GRAND_TOTAL] |
||
| 125 | = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutGrandTotal())->getText()); |
||
| 126 | $this->values[self::VALUE_SUBTOTAL] |
||
| 127 | = trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutSubTotal())->getText()); |
||
| 128 | |||
| 129 | } |
||
| 130 | |||
| 141 | } |
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: