@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | if (false !== $sort) { |
114 | 114 | sort($parts, (int) $sort); |
115 | 115 | } |
116 | - $data[$key] = $parts; |
|
116 | + $data[ $key ] = $parts; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $data; |
@@ -132,37 +132,37 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public static function consolidateFontsArray(array $fonts_array) |
134 | 134 | { |
135 | - $fonts = []; |
|
136 | - $subsets = []; |
|
137 | - $fonts_to_subs = []; |
|
135 | + $fonts = [ ]; |
|
136 | + $subsets = [ ]; |
|
137 | + $fonts_to_subs = [ ]; |
|
138 | 138 | |
139 | - foreach ($fonts_array['complete'] as $font_string) { |
|
139 | + foreach ($fonts_array[ 'complete' ] as $font_string) { |
|
140 | 140 | $parts = explode(':', $font_string); |
141 | - $name = $parts[0]; |
|
142 | - $size = isset($parts[1]) ? $parts[1] : ''; |
|
141 | + $name = $parts[ 0 ]; |
|
142 | + $size = isset($parts[ 1 ]) ? $parts[ 1 ] : ''; |
|
143 | 143 | |
144 | - if (isset($fonts[$name])) { |
|
144 | + if (isset($fonts[ $name ])) { |
|
145 | 145 | // If a name already exists, append the new size |
146 | - $fonts[$name] .= ',' . $size; |
|
146 | + $fonts[ $name ] .= ',' . $size; |
|
147 | 147 | } else { |
148 | 148 | // Create a new key for the name and size |
149 | - $fonts[$name] = $size; |
|
149 | + $fonts[ $name ] = $size; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // Check if subset is specified as the third element |
153 | - if (isset($parts[2])) { |
|
154 | - $subset = $parts[2]; |
|
153 | + if (isset($parts[ 2 ])) { |
|
154 | + $subset = $parts[ 2 ]; |
|
155 | 155 | // Collect all the subsets defined into a single array |
156 | 156 | $elements = explode(',', $subset); |
157 | 157 | foreach ($elements as $sub) { |
158 | - $subsets[] = $sub; |
|
158 | + $subsets[ ] = $sub; |
|
159 | 159 | } |
160 | 160 | // Keeping a separate map of names => requested subsets for |
161 | 161 | // webfontloader purposes |
162 | - if (isset($fonts_to_subs[$name])) { |
|
163 | - $fonts_to_subs[$name] .= ',' . $subset; |
|
162 | + if (isset($fonts_to_subs[ $name ])) { |
|
163 | + $fonts_to_subs[ $name ] .= ',' . $subset; |
|
164 | 164 | } else { |
165 | - $fonts_to_subs[$name] = $subset; |
|
165 | + $fonts_to_subs[ $name ] = $subset; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | // Sanitize and de-dup $fonts_to_subs mapping |
180 | 180 | $fonts_to_subs = self::dedupValues($fonts_to_subs, false); // no sort |
181 | 181 | |
182 | - return [$fonts, $subsets, $fonts_to_subs]; |
|
182 | + return [ $fonts, $subsets, $fonts_to_subs ]; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | $href = self::encodeUnencodedAmpersands($font_url); |
196 | 196 | $markup = '<link rel="stylesheet" type="text/css" href="' . $href . '">'; |
197 | 197 | |
198 | - if (isset($fonts['partial']) && is_array($fonts['partial']['url'])) { |
|
199 | - foreach ($fonts['partial']['url'] as $other) { |
|
198 | + if (isset($fonts[ 'partial' ]) && is_array($fonts[ 'partial' ][ 'url' ])) { |
|
199 | + foreach ($fonts[ 'partial' ][ 'url' ] as $other) { |
|
200 | 200 | $markup .= '<link rel="stylesheet" type="text/css"'; |
201 | 201 | $markup .= ' href="' . self::encodeUnencodedAmpersands($other) . '">'; |
202 | 202 | } |
@@ -215,24 +215,24 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public static function buildFontsMarkupScript(array $fonts) |
217 | 217 | { |
218 | - $families_array = []; |
|
218 | + $families_array = [ ]; |
|
219 | 219 | |
220 | 220 | list($names, $subsets, $mapping) = self::consolidateFontsArray($fonts); |
221 | 221 | foreach ($names as $name => $sizes) { |
222 | 222 | $family = $name . ':' . implode(',', $sizes); |
223 | - if (isset($mapping[$name])) { |
|
224 | - $family .= ':' . implode(',', $mapping[$name]); |
|
223 | + if (isset($mapping[ $name ])) { |
|
224 | + $family .= ':' . implode(',', $mapping[ $name ]); |
|
225 | 225 | } |
226 | - $families_array[] = $family; |
|
226 | + $families_array[ ] = $family; |
|
227 | 227 | } |
228 | 228 | $families = "'" . implode("', '", $families_array) . "'"; |
229 | 229 | |
230 | 230 | // Load 'text' requests with the "custom" module |
231 | 231 | $custom = ''; |
232 | - if (isset($fonts['partial'])) { |
|
232 | + if (isset($fonts[ 'partial' ])) { |
|
233 | 233 | $custom = ",\n custom: {\n"; |
234 | - $custom .= " families: [ '" . implode("', '", $fonts['partial']['name']) . "' ],\n"; |
|
235 | - $custom .= " urls: [ '" . implode("', '", $fonts['partial']['url']) . "' ]\n"; |
|
234 | + $custom .= " families: [ '" . implode("', '", $fonts[ 'partial' ][ 'name' ]) . "' ],\n"; |
|
235 | + $custom .= " urls: [ '" . implode("', '", $fonts[ 'partial' ][ 'url' ]) . "' ]\n"; |
|
236 | 236 | $custom .= ' }'; |
237 | 237 | } |
238 | 238 | |
@@ -287,28 +287,28 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return null|string |
289 | 289 | */ |
290 | - public static function buildGoogleFontsUrl(array $fonts, $subsets = []) |
|
290 | + public static function buildGoogleFontsUrl(array $fonts, $subsets = [ ]) |
|
291 | 291 | { |
292 | 292 | $base_url = 'https://fonts.googleapis.com/css'; |
293 | - $font_args = []; |
|
294 | - $family = []; |
|
293 | + $font_args = [ ]; |
|
294 | + $family = [ ]; |
|
295 | 295 | |
296 | 296 | foreach ($fonts as $font_name => $font_weight) { |
297 | 297 | if (is_array($font_weight)) { |
298 | 298 | $font_weight = implode(',', $font_weight); |
299 | 299 | } |
300 | 300 | // Trimming end colon handles edge case of being given an empty $font_weight |
301 | - $family[] = trim(trim($font_name) . ':' . trim($font_weight), ':'); |
|
301 | + $family[ ] = trim(trim($font_name) . ':' . trim($font_weight), ':'); |
|
302 | 302 | } |
303 | 303 | |
304 | - $font_args['family'] = implode('|', $family); |
|
304 | + $font_args[ 'family' ] = implode('|', $family); |
|
305 | 305 | |
306 | - if (! empty($subsets)) { |
|
306 | + if (!empty($subsets)) { |
|
307 | 307 | if (is_array($subsets)) { |
308 | 308 | $subsets = array_unique($subsets); |
309 | 309 | $subsets = implode(',', $subsets); |
310 | 310 | } |
311 | - $font_args['subset'] = trim($subsets); |
|
311 | + $font_args[ 'subset' ] = trim($subsets); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | $url = $base_url . '?' . http_build_query($font_args); |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | const FILTER_OB_CLEANER = 'zwf_gfo_clean_ob'; |
16 | 16 | const DEFAULT_OB_CLEANER = false; |
17 | 17 | |
18 | - protected $candidates = []; |
|
18 | + protected $candidates = [ ]; |
|
19 | 19 | |
20 | - protected $enqueued = []; |
|
20 | + protected $enqueued = [ ]; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Like the wind. |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * Scan and optimize requests found in the markup (uses more |
36 | 36 | * memory but works on [almost] any theme) |
37 | 37 | */ |
38 | - add_action('template_redirect', [$this, 'startBuffering'], 11); |
|
38 | + add_action('template_redirect', [ $this, 'startBuffering' ], 11); |
|
39 | 39 | break; |
40 | 40 | |
41 | 41 | case self::DEFAULT_OPERATION_MODE: |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * Scan only things added via wp_enqueue_style (uses slightly |
45 | 45 | * less memory usually, but requires a decently coded theme) |
46 | 46 | */ |
47 | - add_filter('print_styles_array', [$this, 'processStylesHandles']); |
|
47 | + add_filter('print_styles_array', [ $this, 'processStylesHandles' ]); |
|
48 | 48 | break; |
49 | 49 | } |
50 | 50 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return bool |
58 | 58 | */ |
59 | - protected function hasEnoughElements(array $candidates = []) |
|
59 | + protected function hasEnoughElements(array $candidates = [ ]) |
|
60 | 60 | { |
61 | 61 | $enough = true; |
62 | 62 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $candidate_handles = $this->findCandidateHandles($handles); |
85 | 85 | |
86 | 86 | // Bail if we don't have anything that makes sense for us to continue |
87 | - if (! $this->hasEnoughElements($candidate_handles)) { |
|
87 | + if (!$this->hasEnoughElements($candidate_handles)) { |
|
88 | 88 | return $handles; |
89 | 89 | } |
90 | 90 | |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | |
94 | 94 | // Get fonts array data from candidates |
95 | 95 | $fonts_array = $this->getFontsArray($this->getCandidates()); |
96 | - if (isset($fonts_array['complete'])) { |
|
96 | + if (isset($fonts_array[ 'complete' ])) { |
|
97 | 97 | $combined_font_url = Utils::buildGoogleFontsUrlFromFontsArray($fonts_array); |
98 | 98 | $handle_name = 'zwf-gfo-combined'; |
99 | 99 | $this->enqueueStyle($handle_name, $combined_font_url); |
100 | - $handles[] = $handle_name; |
|
100 | + $handles[ ] = $handle_name; |
|
101 | 101 | } |
102 | 102 | |
103 | - if (isset($fonts_array['partial'])) { |
|
103 | + if (isset($fonts_array[ 'partial' ])) { |
|
104 | 104 | $cnt = 0; |
105 | - foreach ($fonts_array['partial']['url'] as $url) { |
|
105 | + foreach ($fonts_array[ 'partial' ][ 'url' ] as $url) { |
|
106 | 106 | $cnt++; |
107 | 107 | $handle_name = 'zwf-gfo-combined-txt-' . $cnt; |
108 | 108 | $this->enqueueStyle($handle_name, $url); |
109 | - $handles[] = $handle_name; |
|
109 | + $handles[ ] = $handle_name; |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | public function findCandidateHandles(array $handles) |
135 | 135 | { |
136 | 136 | $handler = /** @scrutinizer ignore-call */ \wp_styles(); |
137 | - $candidate_handles = []; |
|
137 | + $candidate_handles = [ ]; |
|
138 | 138 | |
139 | 139 | foreach ($handles as $handle) { |
140 | 140 | $dep = $handler->query($handle, 'registered'); |
141 | 141 | if ($dep) { |
142 | 142 | $url = $dep->src; |
143 | 143 | if (Utils::isGoogleWebFontUrl($url)) { |
144 | - $candidate_handles[$handle] = $url; |
|
144 | + $candidate_handles[ $handle ] = $url; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | \wp_dequeue_style($handle); |
170 | 170 | } |
171 | 171 | // @codeCoverageIgnoreEnd |
172 | - unset($this->enqueued[$handle]); |
|
172 | + unset($this->enqueued[ $handle ]); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return void |
186 | 186 | */ |
187 | - public function enqueueStyle($handle, $url, $deps = [], $version = null) |
|
187 | + public function enqueueStyle($handle, $url, $deps = [ ], $version = null) |
|
188 | 188 | { |
189 | 189 | // @codeCoverageIgnoreStart |
190 | 190 | if (function_exists('\wp_enqueue_style')) { |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | } |
194 | 194 | // @codeCoverageIgnoreEnd |
195 | 195 | |
196 | - $this->enqueued[$handle] = $url; |
|
196 | + $this->enqueued[ $handle ] = $url; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | { |
208 | 208 | $data = $this->enqueued; |
209 | 209 | |
210 | - if (null !== $handle && isset($this->enqueued[$handle])) { |
|
211 | - $data = $this->enqueued[$handle]; |
|
210 | + if (null !== $handle && isset($this->enqueued[ $handle ])) { |
|
211 | + $data = $this->enqueued[ $handle ]; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return $data; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | public function processMarkup($markup) |
227 | 227 | { |
228 | 228 | $hrefs = $this->parseMarkupForHrefs($markup); |
229 | - if (! empty($hrefs)) { |
|
229 | + if (!empty($hrefs)) { |
|
230 | 230 | $this->setCandidates($hrefs); |
231 | 231 | } |
232 | 232 | |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | $candidates = $this->getCandidates(); |
235 | 235 | |
236 | 236 | // Bail and return original markup unmodified if we don't have things to do |
237 | - if (! $this->hasEnoughElements($candidates)) { |
|
237 | + if (!$this->hasEnoughElements($candidates)) { |
|
238 | 238 | return $markup; |
239 | 239 | } |
240 | 240 | |
241 | 241 | // Process what we found and modify original markup with our replacement |
242 | 242 | $fonts_array = $this->getFontsArray($candidates); |
243 | 243 | $font_markup = $this->buildFontsMarkup($fonts_array); |
244 | - $markup = $this->modifyMarkup($markup, $font_markup, $fonts_array['links']); |
|
244 | + $markup = $this->modifyMarkup($markup, $font_markup, $fonts_array[ 'links' ]); |
|
245 | 245 | |
246 | 246 | return $markup; |
247 | 247 | } |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | */ |
275 | 275 | protected function filterHrefsFromCandidateLinkNodes(\DOMNodeList $nodes) |
276 | 276 | { |
277 | - $hrefs = []; |
|
277 | + $hrefs = [ ]; |
|
278 | 278 | |
279 | 279 | foreach ($nodes as $node) { |
280 | 280 | if ($this->isCandidateLink($node)) { |
281 | - $hrefs[] = $node->getAttribute('href'); |
|
281 | + $hrefs[ ] = $node->getAttribute('href'); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | |
351 | 351 | // Start our own buffering |
352 | - $started = ob_start([$this, 'endBuffering']); |
|
352 | + $started = ob_start([ $this, 'endBuffering' ]); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | return $started; |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | public function endBuffering($markup) |
359 | 359 | { |
360 | 360 | // Bail early on things we don't want to parse |
361 | - if (! $this->isMarkupDoable($markup)) { |
|
361 | + if (!$this->isMarkupDoable($markup)) { |
|
362 | 362 | return $markup; |
363 | 363 | } |
364 | 364 | |
@@ -441,13 +441,13 @@ discard block |
||
441 | 441 | $html5 = Utils::hasHtml5Doctype($content); |
442 | 442 | $xsl = Utils::hasXslStylesheet($content); |
443 | 443 | |
444 | - return (($html || $html5) && ! $xsl); |
|
444 | + return (($html || $html5) && !$xsl); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
448 | 448 | * @param array $urls |
449 | 449 | */ |
450 | - public function setCandidates(array $urls = []) |
|
450 | + public function setCandidates(array $urls = [ ]) |
|
451 | 451 | { |
452 | 452 | $this->candidates = $urls; |
453 | 453 | } |
@@ -468,26 +468,26 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @return array |
470 | 470 | */ |
471 | - protected function getFontsArray(array $candidates = []) |
|
471 | + protected function getFontsArray(array $candidates = [ ]) |
|
472 | 472 | { |
473 | - $fonts = []; |
|
473 | + $fonts = [ ]; |
|
474 | 474 | |
475 | 475 | foreach ($candidates as $candidate) { |
476 | - $fonts['links'][] = $candidate; |
|
476 | + $fonts[ 'links' ][ ] = $candidate; |
|
477 | 477 | |
478 | - $params = []; |
|
478 | + $params = [ ]; |
|
479 | 479 | parse_str(parse_url($candidate, PHP_URL_QUERY), $params); |
480 | 480 | |
481 | - if (isset($params['text'])) { |
|
481 | + if (isset($params[ 'text' ])) { |
|
482 | 482 | // Fonts with character limitations are segregated into |
483 | 483 | // under 'partial' (when `text` query param is used) |
484 | - $font_family = explode(':', $params['family']); |
|
485 | - $fonts['partial']['name'][] = $font_family[0]; |
|
486 | - $fonts['partial']['url'][] = Utils::httpsify($candidate); |
|
484 | + $font_family = explode(':', $params[ 'family' ]); |
|
485 | + $fonts[ 'partial' ][ 'name' ][ ] = $font_family[ 0 ]; |
|
486 | + $fonts[ 'partial' ][ 'url' ][ ] = Utils::httpsify($candidate); |
|
487 | 487 | } else { |
488 | 488 | $fontstrings = $this->buildFontStringsFromQueryParams($params); |
489 | 489 | foreach ($fontstrings as $font) { |
490 | - $fonts['complete'][] = $font; |
|
490 | + $fonts[ 'complete' ][ ] = $font; |
|
491 | 491 | } |
492 | 492 | } |
493 | 493 | } |
@@ -506,12 +506,12 @@ discard block |
||
506 | 506 | */ |
507 | 507 | protected function buildFontStringsFromQueryParams(array $params) |
508 | 508 | { |
509 | - $fonts = []; |
|
509 | + $fonts = [ ]; |
|
510 | 510 | |
511 | - foreach (explode('|', $params['family']) as $family) { |
|
511 | + foreach (explode('|', $params[ 'family' ]) as $family) { |
|
512 | 512 | $font = $this->parseFontStringFamilyParam($family, $params); |
513 | - if (! empty($font)) { |
|
514 | - $fonts[] = $font; |
|
513 | + if (!empty($font)) { |
|
514 | + $fonts[ ] = $font; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | $subset = false; |
530 | 530 | $family = explode(':', $family); |
531 | 531 | |
532 | - if (isset($params['subset'])) { |
|
532 | + if (isset($params[ 'subset' ])) { |
|
533 | 533 | // Use the found subset query parameter |
534 | - $subset = $params['subset']; |
|
535 | - } elseif (isset($family[2])) { |
|
534 | + $subset = $params[ 'subset' ]; |
|
535 | + } elseif (isset($family[ 2 ])) { |
|
536 | 536 | // Use the subset in the family string if present |
537 | - $subset = $family[2]; |
|
537 | + $subset = $family[ 2 ]; |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | // $family can have a lot of thing specified with separators etc. |
@@ -554,19 +554,19 @@ discard block |
||
554 | 554 | */ |
555 | 555 | protected function buildFontStringParts(array $family, $subset = false) |
556 | 556 | { |
557 | - $parts = []; |
|
557 | + $parts = [ ]; |
|
558 | 558 | |
559 | 559 | // First part is the font name, which should always be present |
560 | - $parts[] = $family[0]; |
|
560 | + $parts[ ] = $family[ 0 ]; |
|
561 | 561 | |
562 | 562 | // Check if sizes are specified |
563 | - if (isset($family[1]) && strlen($family[1]) > 0) { |
|
564 | - $parts[] = $family[1]; |
|
563 | + if (isset($family[ 1 ]) && strlen($family[ 1 ]) > 0) { |
|
564 | + $parts[ ] = $family[ 1 ]; |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | // Add the subset if specified |
568 | 568 | if ($subset) { |
569 | - $parts[] = $subset; |
|
569 | + $parts[ ] = $subset; |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | return $parts; |