We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 7 |
Paths | 5 |
Total Lines | 62 |
Code Lines | 32 |
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 |
||
125 | protected function getUrlTemplate() |
||
126 | { |
||
127 | // Should work for route enhancers like this: |
||
128 | // |
||
129 | // routeEnhancers: |
||
130 | // KitodoWorkview: |
||
131 | // type: Plugin |
||
132 | // namespace: tx_dlf |
||
133 | // routePath: '/{page}/{double}' |
||
134 | // requirements: |
||
135 | // page: \d+ |
||
136 | // double: 0|1 |
||
137 | |||
138 | $make = function ($page, $double, $pagegrid) { |
||
139 | $result = $this->uriBuilder->reset() |
||
140 | ->setTargetPageUid($GLOBALS['TSFE']->id) |
||
141 | ->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? true : false) |
||
142 | ->setArguments([ |
||
143 | 'tx_dlf' => array_merge($this->requestData, [ |
||
144 | 'page' => $page, |
||
145 | 'double' => $double, |
||
146 | 'pagegrid' => $pagegrid |
||
147 | ]), |
||
148 | ]) |
||
149 | ->build(); |
||
150 | |||
151 | $cHashIdx = strpos($result, '&cHash='); |
||
152 | if ($cHashIdx !== false) { |
||
153 | $result = substr($result, 0, $cHashIdx); |
||
154 | } |
||
155 | |||
156 | return $result; |
||
157 | }; |
||
158 | |||
159 | // Generate two URLs that differ in tx_dlf[page], tx_dlf[double] and tx_dlf[highlight]. |
||
160 | // We don't know the order of these parameters, so use the values for matching. |
||
161 | $a = $make(2, 1, 0); |
||
162 | $b = $make(3, 0, 1); |
||
163 | |||
164 | $lastIdx = 0; |
||
165 | $result = ''; |
||
166 | for ($i = 0, $len = strlen($a); $i < $len; $i++) { |
||
167 | if ($a[$i] === $b[$i]) { |
||
168 | continue; |
||
169 | } |
||
170 | |||
171 | $result .= substr($a, $lastIdx, $i - $lastIdx); |
||
172 | $lastIdx = $i + 1; |
||
173 | |||
174 | if ($a[$i] === '2') { |
||
175 | $placeholder = 'PAGE_NO'; |
||
176 | } else if ($a[$i] === '1') { |
||
177 | $placeholder = 'DOUBLE_PAGE'; |
||
178 | } else { |
||
179 | $placeholder = 'PAGE_GRID'; |
||
180 | } |
||
181 | |||
182 | $result .= $placeholder; |
||
183 | } |
||
184 | $result .= substr($a, $lastIdx); |
||
185 | |||
186 | return $result; |
||
187 | } |
||
190 |