| Conditions | 6 |
| Paths | 5 |
| Total Lines | 67 |
| Code Lines | 53 |
| 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 |
||
| 108 | public function leafletJsTileLayers(): array |
||
| 109 | { |
||
| 110 | $api_key = $this->getPreference('api_key'); |
||
| 111 | |||
| 112 | if ($api_key === '') { |
||
| 113 | $message = I18N::translate('This service requires an API key.'); |
||
| 114 | |||
| 115 | if (Auth::isAdmin()) { |
||
| 116 | $message = '<a href="' . e($this->getConfigLink()) . '">' . $message . '</a>'; |
||
| 117 | } |
||
| 118 | |||
| 119 | throw new HttpServerErrorException($message); |
||
| 120 | } |
||
| 121 | |||
| 122 | $tag = I18N::languageTag(); |
||
| 123 | $lang2 = 'en'; |
||
| 124 | foreach (self::LANGUAGE_CODES as $code) { |
||
| 125 | if ($tag === $lang2 || str_starts_with($tag, $code . '-')) { |
||
| 126 | $lang2 = $code; |
||
| 127 | break; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | return [ |
||
| 132 | (object) [ |
||
| 133 | 'apiKey' => $api_key, |
||
| 134 | 'attribution' => '©2024 HERE Technologies', |
||
| 135 | 'label' => 'Day', |
||
| 136 | 'maxZoom' => 18, |
||
| 137 | 'minZoom' => 2, |
||
| 138 | 'lang2' => $lang2, |
||
| 139 | 'url' => "https://maps.hereapi.com/v3/base/mc/{z}/{x}/{y}/jpeg?size=256&style={variant}&lang2={lang2}&apiKey={apiKey}", |
||
| 140 | 'variant' => 'explore.day', |
||
| 141 | 'localName' => 'HEREDay', |
||
| 142 | ], |
||
| 143 | (object) [ |
||
| 144 | 'apiKey' => $api_key, |
||
| 145 | 'attribution' => '©2024 HERE Technologies', |
||
| 146 | 'label' => 'Satellite Day', |
||
| 147 | 'maxZoom' => 18, |
||
| 148 | 'minZoom' => 2, |
||
| 149 | 'lang2' => $lang2, |
||
| 150 | 'url' => "https://maps.hereapi.com/v3/base/mc/{z}/{x}/{y}/jpeg?size=256&style={variant}&lang2={lang2}&apiKey={apiKey}", |
||
| 151 | 'variant' => 'explore.satellite.day', |
||
| 152 | 'localName' => 'HEREDSatelliteDay', |
||
| 153 | ], |
||
| 154 | (object) [ |
||
| 155 | 'apiKey' => $api_key, |
||
| 156 | 'attribution' => '©2024 HERE Technologies', |
||
| 157 | 'label' => 'Night', |
||
| 158 | 'maxZoom' => 18, |
||
| 159 | 'minZoom' => 2, |
||
| 160 | 'lang2' => $lang2, |
||
| 161 | 'url' => "https://maps.hereapi.com/v3/base/mc/{z}/{x}/{y}/jpeg?size=256&style={variant}&lang2={lang2}&apiKey={apiKey}", |
||
| 162 | 'variant' => 'explore.night', |
||
| 163 | 'localName' => 'HERENight', |
||
| 164 | ], |
||
| 165 | (object) [ |
||
| 166 | 'apiKey' => $api_key, |
||
| 167 | 'attribution' => '©2024 HERE Technologies', |
||
| 168 | 'label' => 'Terrain', |
||
| 169 | 'maxZoom' => 18, |
||
| 170 | 'minZoom' => 2, |
||
| 171 | 'lang2' => $lang2, |
||
| 172 | 'url' => "https://maps.hereapi.com/v3/base/mc/{z}/{x}/{y}/jpeg?size=256&style={variant}&lang2={lang2}&apiKey={apiKey}", |
||
| 173 | 'variant' => 'topo.day', |
||
| 174 | 'localName' => 'HERETerrain', |
||
| 175 | ], |
||
| 179 |