Conditions | 15 |
Paths | 33 |
Total Lines | 80 |
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 |
||
34 | public function getRecords($startPage, $basePages, SitemapController $obj): array |
||
35 | { |
||
36 | $nodes = []; |
||
37 | foreach ($basePages as $uid) { |
||
38 | // If currently in another language than default, check if the page is translated - else continue |
||
39 | if ($GLOBALS['TSFE']->sys_language_uid != 0) { |
||
40 | $localizedPagesTable = 'pages'; |
||
41 | |||
42 | // in TYPO3 6.x the localization isn't correctly handled when using BackendUtility::getRecordLocalization('pages') |
||
43 | // so we have to use the 'pages_language_overlay' table as param |
||
44 | if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < 7000000) { |
||
45 | $localizedPagesTable = 'pages_language_overlay'; |
||
46 | } |
||
47 | |||
48 | if (BackendUtility::getRecordLocalization($localizedPagesTable, $uid, $GLOBALS['TSFE']->sys_language_uid) == false) { |
||
49 | continue; |
||
50 | } |
||
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 | // exclude Doctypes |
||
67 | if (in_array($record['doktype'], [ |
||
68 | PageRepository::DOKTYPE_LINK, |
||
69 | PageRepository::DOKTYPE_SHORTCUT, |
||
70 | PageRepository::DOKTYPE_SPACER |
||
71 | ])) { |
||
72 | continue; |
||
73 | } |
||
74 | |||
75 | // Exclude pages with exclude flag |
||
76 | if ($record['exclude_sitemap']) { |
||
77 | continue; |
||
78 | } |
||
79 | |||
80 | // Check FE Access |
||
81 | if ($record['fe_group'] != 0 || $record['no_search'] != 0) { |
||
82 | continue; |
||
83 | } |
||
84 | |||
85 | $rootLineList = $GLOBALS['TSFE']->sys_page->getRootLine($record['uid']); |
||
86 | $addToNode = true; |
||
87 | foreach ($rootLineList as $rootPage) { |
||
88 | if ($rootPage['extendToSubpages'] == 1 && ($rootPage['fe_group'] != 0 || $rootPage['no_search'] != 0)) { |
||
89 | $addToNode = false; |
||
90 | break; |
||
91 | } |
||
92 | } |
||
93 | if ($addToNode === false) { |
||
94 | continue; |
||
95 | } |
||
96 | |||
97 | // Build Node |
||
98 | $node = new Node(); |
||
99 | $node->setPid($uid); |
||
100 | $node->setLoc($url); |
||
101 | $node->setPriority($this->getPriority($startPage, $record)); |
||
102 | $node->setChangefreq(SitemapDataService::mapTimeout2Period($record['cache_timeout'])); |
||
103 | $node->setLastmod($this->getModifiedDate($record)); |
||
104 | |||
105 | #$geo = new Geo(); |
||
106 | #$geo->setFormat('kml'); |
||
107 | #$node->setGeo($geo); |
||
108 | |||
109 | $nodes[] = $node; |
||
110 | } |
||
111 | |||
112 | return $nodes; |
||
113 | } |
||
114 | |||
176 |