| Conditions | 14 |
| Paths | 2 |
| Total Lines | 45 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 30 |
| CRAP Score | 14.0478 |
| 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 |
||
| 62 | 26 | public function findPrice(PriceCollection $prices) |
|
| 63 | { |
||
| 64 | 26 | $currency = $this->currency; |
|
| 65 | 26 | $country = $this->country; |
|
| 66 | 26 | $customerGroup = $this->customerGroup; |
|
| 67 | 26 | $channel = $this->channel; |
|
| 68 | |||
| 69 | 26 | $prices = new \CallbackFilterIterator( |
|
| 70 | 26 | $prices, |
|
| 71 | 26 | function ($price) use ($currency, $country, $customerGroup, $channel) { |
|
| 72 | 26 | if (!$this->priceHasCurrency($price, $currency)) { |
|
| 73 | 24 | return false; |
|
| 74 | } |
||
| 75 | 26 | if (!$this->priceHasNoDate($price) && !$this->priceHasValidDate($price, new \DateTime())) { |
|
| 76 | return false; |
||
| 77 | } |
||
| 78 | 26 | if (is_null($country)) { |
|
|
1 ignored issue
–
show
|
|||
| 79 | 6 | if ($this->priceHas($price, 'country')) { |
|
| 80 | 6 | return false; |
|
| 81 | } |
||
| 82 | 20 | } elseif (!$this->priceHasCountry($price, $country)) { |
|
| 83 | 18 | return false; |
|
| 84 | } |
||
| 85 | 26 | if (is_null($customerGroup)) { |
|
| 86 | 12 | if ($this->priceHas($price, 'customerGroup')) { |
|
| 87 | 12 | return false; |
|
| 88 | } |
||
| 89 | 14 | } elseif (!$this->priceHasCustomerGroup($price, $customerGroup)) { |
|
| 90 | 12 | return false; |
|
| 91 | } |
||
| 92 | 26 | if (is_null($channel)) { |
|
| 93 | 12 | if ($this->priceHas($price, 'channel')) { |
|
| 94 | 12 | return false; |
|
| 95 | } |
||
| 96 | 14 | } elseif (!$this->priceHasChannel($price, $channel)) { |
|
| 97 | 9 | return false; |
|
| 98 | } |
||
| 99 | 26 | return true; |
|
| 100 | 26 | } |
|
| 101 | ); |
||
| 102 | |||
| 103 | 26 | foreach ($prices as $price) { |
|
| 104 | 26 | return $price; |
|
| 105 | } |
||
| 106 | return null; |
||
| 107 | } |
||
| 200 |