| Conditions | 7 |
| Paths | 35 |
| Total Lines | 65 |
| Code Lines | 36 |
| 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 |
||
| 139 | public function exportDynamicStreams(\Shopware_Components_Cron_CronJob $job) |
||
| 140 | { |
||
| 141 | /** @var ProductStreamService $streamService */ |
||
| 142 | $streamService = $this->getStreamService(); |
||
| 143 | $streams = $streamService->getAllExportedStreams(ProductStreamService::DYNAMIC_STREAM); |
||
| 144 | |||
| 145 | /** @var ProductStream $stream */ |
||
| 146 | foreach ($streams as $stream) { |
||
| 147 | $streamId = $stream->getId(); |
||
| 148 | $productSearchResult = $streamService->getProductFromConditionStream($stream); |
||
| 149 | $orderNumbers = array_keys($productSearchResult->getProducts()); |
||
| 150 | |||
| 151 | //no products found |
||
| 152 | if (!$orderNumbers) { |
||
| 153 | //removes all products from this stream |
||
| 154 | $streamService->markProductsToBeRemovedFromStream($streamId); |
||
| 155 | } else { |
||
| 156 | $articleIds = $this->helper->getArticleIdsByNumber($orderNumbers); |
||
| 157 | |||
| 158 | $streamService->markProductsToBeRemovedFromStream($streamId); |
||
| 159 | $streamService->createStreamRelation($streamId, $articleIds); |
||
| 160 | } |
||
| 161 | |||
| 162 | try { |
||
| 163 | $streamsAssignments = $streamService->prepareStreamsAssignments($streamId, false); |
||
| 164 | |||
| 165 | //article ids must be taken from streamsAssignments |
||
| 166 | $exportArticleIds = $streamsAssignments->getArticleIds(); |
||
| 167 | |||
| 168 | $removeArticleIds = $streamsAssignments->getArticleIdsWithoutStreams(); |
||
| 169 | |||
| 170 | if (!empty($removeArticleIds)) { |
||
| 171 | $this->removeArticlesFromStream($removeArticleIds); |
||
| 172 | |||
| 173 | //filter the $exportArticleIds |
||
| 174 | $exportArticleIds = array_diff($exportArticleIds, $removeArticleIds); |
||
| 175 | } |
||
| 176 | |||
| 177 | $sourceIds = $this->helper->getArticleSourceIds($exportArticleIds); |
||
| 178 | |||
| 179 | $errorMessages = $this->connectExport->export($sourceIds, $streamsAssignments); |
||
| 180 | $streamService->changeStatus($streamId, ProductStreamService::STATUS_EXPORT); |
||
| 181 | } catch (\RuntimeException $e) { |
||
| 182 | $streamService->changeStatus($streamId, ProductStreamService::STATUS_ERROR); |
||
| 183 | $streamService->log($streamId, $e->getMessage()); |
||
| 184 | continue; |
||
| 185 | } |
||
| 186 | |||
| 187 | if ($errorMessages) { |
||
| 188 | $streamService->changeStatus($streamId, ProductStreamService::STATUS_ERROR); |
||
| 189 | |||
| 190 | $errorMessagesText = ''; |
||
| 191 | $displayedErrorTypes = [ |
||
| 192 | ErrorHandler::TYPE_DEFAULT_ERROR, |
||
| 193 | ErrorHandler::TYPE_PRICE_ERROR |
||
| 194 | ]; |
||
| 195 | |||
| 196 | foreach ($displayedErrorTypes as $displayedErrorType) { |
||
| 197 | $errorMessagesText .= implode('\n', $errorMessages[$displayedErrorType]); |
||
| 198 | } |
||
| 199 | |||
| 200 | $streamService->log($streamId, $errorMessagesText); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 234 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.