Conditions | 14 |
Paths | 22 |
Total Lines | 71 |
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 |
||
63 | public function getRecords($startPage, $basePages, SitemapController $obj): array |
||
64 | { |
||
65 | $nodes = []; |
||
66 | foreach ($basePages as $uid) { |
||
67 | if ($this->currentLanguageUid) { |
||
68 | $fields = $this->cObject->enableFields('pages_language_overlay'); |
||
69 | $overlay = $this->database->exec_SELECTgetSingleRow( |
||
70 | 'uid', |
||
71 | 'pages_language_overlay', |
||
72 | ' pid=' . intval($uid) . ' AND sys_language_uid=' . $this->currentLanguageUid . $fields |
||
73 | ); |
||
74 | if (!is_array($overlay)) { |
||
75 | continue; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | // Build URL |
||
80 | $url = $obj->getUriBuilder() |
||
81 | ->setTargetPageUid($uid) |
||
82 | ->build(); |
||
83 | |||
84 | // can't generate a valid url |
||
85 | if (!strlen($url)) { |
||
86 | continue; |
||
87 | } |
||
88 | |||
89 | // Get Record |
||
90 | $record = BackendUtility::getRecord('pages', $uid); |
||
91 | |||
92 | // exclude Doctypes |
||
93 | if (in_array($record['doktype'], [4])) { |
||
94 | continue; |
||
95 | } |
||
96 | |||
97 | // Check FE Access |
||
98 | if ($record['fe_group'] != 0 || $record['no_search'] != 0) { |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | if ($record['exclude_sitemap']) { |
||
103 | continue; |
||
104 | } |
||
105 | |||
106 | $rootLineList = $GLOBALS['TSFE']->sys_page->getRootLine($record['uid']); |
||
107 | $addToNode = true; |
||
108 | foreach ($rootLineList as $rootPage) { |
||
109 | if ($rootPage['extendToSubpages'] == 1 && ($rootPage['fe_group'] != 0 || $record['no_search'] != 0)) { |
||
110 | $addToNode = false; |
||
111 | break; |
||
112 | } |
||
113 | } |
||
114 | if ($addToNode === false) { |
||
115 | continue; |
||
116 | } |
||
117 | |||
118 | // Build Node |
||
119 | $node = new Node(); |
||
120 | $node->setLoc($url); |
||
121 | $node->setPriority($this->getPriority($startPage, $record)); |
||
122 | $node->setChangefreq(SitemapDataService::mapTimeout2Period($record['cache_timeout'])); |
||
123 | $node->setLastmod($this->getModifiedDate($record)); |
||
124 | |||
125 | #$geo = new Geo(); |
||
126 | #$geo->setFormat('kml'); |
||
127 | #$node->setGeo($geo); |
||
128 | |||
129 | $nodes[] = $node; |
||
130 | } |
||
131 | |||
132 | return $nodes; |
||
133 | } |
||
134 | } |
||
135 |