| Conditions | 10 |
| Paths | 25 |
| Total Lines | 52 |
| Code Lines | 28 |
| 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 declare(strict_types=1); |
||
| 112 | private function extractIds(LandingPageRouteResponse $response): array |
||
| 113 | { |
||
| 114 | $page = $response->getLandingPage()->getCmsPage(); |
||
| 115 | |||
| 116 | if ($page === null) { |
||
| 117 | return []; |
||
| 118 | } |
||
| 119 | |||
| 120 | $ids = []; |
||
| 121 | $streamIds = []; |
||
| 122 | |||
| 123 | $slots = $page->getElementsOfType('product-slider'); |
||
| 124 | /** @var CmsSlotEntity $slot */ |
||
| 125 | foreach ($slots as $slot) { |
||
| 126 | $slider = $slot->getData(); |
||
| 127 | |||
| 128 | if (!$slider instanceof ProductSliderStruct) { |
||
| 129 | continue; |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($slider->getStreamId() !== null) { |
||
| 133 | $streamIds[] = $slider->getStreamId(); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($slider->getProducts() === null) { |
||
| 137 | continue; |
||
| 138 | } |
||
| 139 | foreach ($slider->getProducts() as $product) { |
||
| 140 | $ids[] = $product->getId(); |
||
| 141 | $ids[] = $product->getParentId(); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | $slots = $page->getElementsOfType('product-box'); |
||
| 146 | /** @var CmsSlotEntity $slot */ |
||
| 147 | foreach ($slots as $slot) { |
||
| 148 | $box = $slot->getData(); |
||
| 149 | |||
| 150 | if (!$box instanceof ProductBoxStruct) { |
||
| 151 | continue; |
||
| 152 | } |
||
| 153 | if ($box->getProduct() === null) { |
||
| 154 | continue; |
||
| 155 | } |
||
| 156 | |||
| 157 | $ids[] = $box->getProduct()->getId(); |
||
| 158 | $ids[] = $box->getProduct()->getParentId(); |
||
| 159 | } |
||
| 160 | |||
| 161 | $ids = array_values(array_unique(array_filter($ids))); |
||
| 162 | |||
| 163 | return [...array_map(EntityCacheKeyGenerator::buildProductTag(...), $ids), ...array_map(EntityCacheKeyGenerator::buildStreamTag(...), $streamIds), ...[EntityCacheKeyGenerator::buildCmsTag($page->getId())]]; |
||
|
|
|||
| 164 | } |
||
| 166 |