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