| Conditions | 12 |
| Paths | 28 |
| Total Lines | 52 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 29 | public function getItem(string $key): ExtendedCacheItemInterface |
||
| 30 | { |
||
| 31 | /** @var ExtendedCacheItemPoolInterface[] $poolsToResync */ |
||
| 32 | $poolsToResync = []; |
||
| 33 | /** @var ?ExtendedCacheItemInterface $item */ |
||
| 34 | $item = null; |
||
| 35 | |||
| 36 | foreach ($this->clusterPools as $driverPool) { |
||
| 37 | $poolItem = $driverPool->getItem($key); |
||
| 38 | if ($poolItem->isHit()) { |
||
| 39 | if (!$item) { |
||
| 40 | $item = $poolItem; |
||
| 41 | continue; |
||
| 42 | } |
||
| 43 | |||
| 44 | $itemData = $item->get(); |
||
| 45 | $poolItemData = $poolItem->get(); |
||
| 46 | |||
| 47 | if (\is_object($itemData) |
||
| 48 | ) { |
||
| 49 | if ($item->get() != $poolItemData) { |
||
| 50 | $poolsToResync[] = $driverPool; |
||
| 51 | } |
||
| 52 | } else { |
||
| 53 | if ($item->get() !== $poolItemData) { |
||
| 54 | $poolsToResync[] = $driverPool; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | $poolsToResync[] = $driverPool; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($item && $item->isHit() && \count($poolsToResync) < \count($this->clusterPools)) { |
||
| 63 | foreach ($poolsToResync as $poolToResync) { |
||
| 64 | $poolItem = $poolToResync->getItem($key); |
||
| 65 | $poolItem->setEventManager($this->getEventManager()) |
||
| 66 | ->set($item->get()) |
||
| 67 | ->setHit($item->isHit()) |
||
| 68 | ->setTags($item->getTags()) |
||
| 69 | ->expiresAt($item->getExpirationDate()) |
||
| 70 | ->setDriver($poolToResync); |
||
| 71 | $poolToResync->save($poolItem); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($item === null) { |
||
| 76 | $item = new Item($this, $key, $this->getEventManager()); |
||
| 77 | $item->expiresAfter(abs($this->getConfig()->getDefaultTtl())); |
||
|
|
|||
| 78 | } |
||
| 79 | |||
| 80 | return $this->getStandardizedItem($item, $this); |
||
| 81 | } |
||
| 177 |