| Conditions | 11 |
| Paths | 10 |
| Total Lines | 57 |
| 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 |
||
| 33 | public function getRecords($startPage, $basePages, SitemapController $obj): array |
||
| 34 | { |
||
| 35 | $nodes = []; |
||
| 36 | $database = $this->getDatabaseConnection(); |
||
| 37 | /** @var PageRepository $pageRepository */ |
||
| 38 | $pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
||
| 39 | $rows = $database->exec_SELECTgetRows('*', 'tt_content', 'CType=' . $database->fullQuoteStr( |
||
| 40 | 'list', |
||
| 41 | 'tt_content' |
||
| 42 | ) . ' AND list_type=' . $database->fullQuoteStr( |
||
| 43 | 'googleservices_pisitemap', |
||
| 44 | 'tt_content' |
||
| 45 | ) . $pageRepository->enableFields('tt_content')); |
||
| 46 | |||
| 47 | foreach ($rows as $row) { |
||
|
|
|||
| 48 | $uid = $row['pid']; |
||
| 49 | if ($uid == $GLOBALS['TSFE']->id) { |
||
| 50 | continue; |
||
| 51 | } |
||
| 52 | |||
| 53 | // Build URL |
||
| 54 | $url = $obj->getUriBuilder() |
||
| 55 | ->setTargetPageUid($uid) |
||
| 56 | ->build(); |
||
| 57 | |||
| 58 | // can't generate a valid url |
||
| 59 | if (!strlen($url)) { |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | |||
| 63 | // Get Record |
||
| 64 | $record = BackendUtility::getRecord('pages', $uid); |
||
| 65 | |||
| 66 | // Check FE Access |
||
| 67 | if ($record['fe_group'] != 0 || $record['no_search'] != 0) { |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | $rootLineList = $GLOBALS['TSFE']->sys_page->getRootLine($record['uid']); |
||
| 71 | $addToNode = true; |
||
| 72 | foreach ($rootLineList as $rootPage) { |
||
| 73 | if ($rootPage['extendToSubpages'] == 1 && ($rootPage['fe_group'] != 0 || $record['no_search'] != 0)) { |
||
| 74 | $addToNode = false; |
||
| 75 | break; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | if ($addToNode === false) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | |||
| 82 | // Build Node |
||
| 83 | $node = new Node(); |
||
| 84 | $node->setLoc($url); |
||
| 85 | $node->setLastmod($this->getModifiedDate($record)); |
||
| 86 | $nodes[] = $node; |
||
| 87 | } |
||
| 88 | return $nodes; |
||
| 89 | } |
||
| 90 | |||
| 121 |
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.