| Conditions | 6 |
| Paths | 8 |
| Total Lines | 54 |
| 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 |
||
| 50 | public function getRecords($startPage, $basePages, SitemapController $obj): array |
||
| 51 | { |
||
| 52 | $nodes = []; |
||
| 53 | foreach ($basePages as $uid) { |
||
| 54 | $images = $this->getImagesByPages([$uid]); |
||
| 55 | if (!sizeof($images)) { |
||
| 56 | continue; |
||
| 57 | } |
||
| 58 | $imageNodes = []; |
||
| 59 | foreach ($images as $imageReference) { |
||
| 60 | /** @var $imageReference \TYPO3\CMS\Core\Resource\FileReference */ |
||
| 61 | $url = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/' . $imageReference->getOriginalFile() |
||
| 62 | ->getPublicUrl(); |
||
| 63 | |||
| 64 | // Build Node |
||
| 65 | $nodeImage = new ImageNode(); |
||
| 66 | $nodeImage->setLoc($url); |
||
| 67 | $nodeImage->setTitle($imageReference->getTitle()); |
||
| 68 | $nodeImage->setCaption($imageReference->getDescription()); |
||
| 69 | $imageNodes[] = $nodeImage; |
||
| 70 | } |
||
| 71 | |||
| 72 | // Build URL |
||
| 73 | $url = $obj->getUriBuilder() |
||
| 74 | ->setTargetPageUid($uid) |
||
| 75 | ->build(); |
||
| 76 | |||
| 77 | // can't generate a valid url |
||
| 78 | if (!strlen($url)) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | |||
| 82 | // Get Record |
||
| 83 | $record = BackendUtility::getRecord('pages', $uid); |
||
| 84 | |||
| 85 | // exclude Doctypes |
||
| 86 | if (in_array($record['doktype'], [4])) { |
||
| 87 | continue; |
||
| 88 | } |
||
| 89 | |||
| 90 | // Build Node |
||
| 91 | $node = new Node(); |
||
| 92 | $node->setLoc($url); |
||
| 93 | $node->setPriority($this->getPriority($startPage, $record)); |
||
| 94 | $node->setChangefreq(SitemapDataService::mapTimeout2Period($record['cache_timeout'])); |
||
| 95 | $node->setLastmod($this->getModifiedDate($record)); |
||
| 96 | $node->setImages($imageNodes); |
||
| 97 | |||
| 98 | |||
| 99 | $nodes[] = $node; |
||
| 100 | } |
||
| 101 | |||
| 102 | return $nodes; |
||
| 103 | } |
||
| 104 | |||
| 156 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.