| Conditions | 11 |
| Paths | 11 |
| Total Lines | 41 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 55 | public function write(array $items) |
||
| 56 | { |
||
| 57 | $uniqueItems = []; |
||
| 58 | $uniqueKeys = []; |
||
| 59 | foreach ($items as $item) { |
||
| 60 | if ($item instanceof Customer) { |
||
| 61 | //GuestCustomerStrategy checks both email and channel |
||
| 62 | if ($item->isGuest()) { |
||
| 63 | $channel = $item->getChannel(); |
||
| 64 | $identifier = preg_replace('/[^a-zA-Z0-9\.]/', '', $item->getEmail()); |
||
| 65 | //set unique identifier: email and channel id |
||
| 66 | if ($channel) { |
||
| 67 | $identifier.=$channel->getId(); |
||
| 68 | } |
||
| 69 | } else { |
||
| 70 | $identifier = $item->getOriginId(); |
||
| 71 | } |
||
| 72 | $this->handleIdentifier($uniqueItems, $item, $identifier); |
||
| 73 | } elseif ($item instanceof Cart) { |
||
| 74 | $this->handleIdentifier($uniqueItems, $item, $item->getOriginId()); |
||
| 75 | } elseif ($item instanceof Order) { |
||
| 76 | $this->handleIdentifier($uniqueItems, $item, $item->getIncrementId()); |
||
| 77 | } elseif ($item instanceof NewsletterSubscriber) { |
||
| 78 | $identifier = $item->getCustomer() ? $item->getCustomer()->getId() : 0; |
||
| 79 | if ($identifier !== 0 && in_array($identifier, $uniqueKeys)) { |
||
| 80 | $this->logSkipped($item->getOriginId()); |
||
| 81 | } else { |
||
| 82 | $uniqueKeys[] = $identifier; |
||
| 83 | $uniqueItems[] = $item; |
||
| 84 | } |
||
| 85 | |||
| 86 | } else { |
||
| 87 | $uniqueItems[] = $item; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | $this->writer->write($uniqueItems); |
||
| 92 | |||
| 93 | // force entity cache clear if clear is skipped |
||
| 94 | $this->databaseHelper->onClear(); |
||
| 95 | } |
||
| 96 | |||
| 145 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: