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