@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | const FILTER_OB_CLEANER = 'zwf_gfo_clean_ob'; |
14 | 14 | const DEFAULT_OB_CLEANER = false; |
15 | 15 | |
16 | - protected $candidates = []; |
|
16 | + protected $candidates = [ ]; |
|
17 | 17 | |
18 | - protected $enqueued = []; |
|
18 | + protected $enqueued = [ ]; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Like the wind. |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * Scan and optimize requests found in the markup (uses more |
34 | 34 | * memory but works on [almost] any theme) |
35 | 35 | */ |
36 | - add_action('template_redirect', [$this, 'startBuffering'], 11); |
|
36 | + add_action('template_redirect', [ $this, 'startBuffering' ], 11); |
|
37 | 37 | break; |
38 | 38 | |
39 | 39 | case self::DEFAULT_OPERATION_MODE: |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * Scan only things added via wp_enqueue_style (uses slightly |
43 | 43 | * less memory usually, but requires a decently coded theme) |
44 | 44 | */ |
45 | - add_filter('print_styles_array', [$this, 'processStylesHandles']); |
|
45 | + add_filter('print_styles_array', [ $this, 'processStylesHandles' ]); |
|
46 | 46 | break; |
47 | 47 | } |
48 | 48 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - protected function hasEnoughElements(array $candidates = []) |
|
57 | + protected function hasEnoughElements(array $candidates = [ ]) |
|
58 | 58 | { |
59 | 59 | $enough = true; |
60 | 60 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $candidate_handles = $this->findCandidateHandles($handles); |
83 | 83 | |
84 | 84 | // Bail if we don't have anything that makes sense for us to continue |
85 | - if (! $this->hasEnoughElements($candidate_handles)) { |
|
85 | + if (!$this->hasEnoughElements($candidate_handles)) { |
|
86 | 86 | return $handles; |
87 | 87 | } |
88 | 88 | |
@@ -91,20 +91,20 @@ discard block |
||
91 | 91 | |
92 | 92 | // Get fonts array data from candidates |
93 | 93 | $fonts_array = $this->getFontsArray($this->getCandidates()); |
94 | - if (isset($fonts_array['complete'])) { |
|
94 | + if (isset($fonts_array[ 'complete' ])) { |
|
95 | 95 | $combined_font_url = $this->buildGoogleFontsUrlFromFontsArray($fonts_array); |
96 | 96 | $handle_name = 'zwf-gfo-combined'; |
97 | 97 | $this->enqueueStyle($handle_name, $combined_font_url); |
98 | - $handles[] = $handle_name; |
|
98 | + $handles[ ] = $handle_name; |
|
99 | 99 | } |
100 | 100 | |
101 | - if (isset($fonts_array['partial'])) { |
|
101 | + if (isset($fonts_array[ 'partial' ])) { |
|
102 | 102 | $cnt = 0; |
103 | - foreach ($fonts_array['partial']['url'] as $url) { |
|
103 | + foreach ($fonts_array[ 'partial' ][ 'url' ] as $url) { |
|
104 | 104 | $cnt++; |
105 | 105 | $handle_name = 'zwf-gfo-combined-txt-' . $cnt; |
106 | 106 | $this->enqueueStyle($handle_name, $url); |
107 | - $handles[] = $handle_name; |
|
107 | + $handles[ ] = $handle_name; |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | public function findCandidateHandles(array $handles) |
133 | 133 | { |
134 | 134 | $handler = /** @scrutinizer ignore-call */ \wp_styles(); |
135 | - $candidate_handles = []; |
|
135 | + $candidate_handles = [ ]; |
|
136 | 136 | |
137 | 137 | foreach ($handles as $handle) { |
138 | 138 | $dep = $handler->query($handle, 'registered'); |
139 | 139 | if ($dep) { |
140 | 140 | $url = $dep->src; |
141 | 141 | if ($this->isGoogleWebFontUrl($url)) { |
142 | - $candidate_handles[$handle] = $url; |
|
142 | + $candidate_handles[ $handle ] = $url; |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | \wp_dequeue_style($handle); |
168 | 168 | } |
169 | 169 | // @codeCoverageIgnoreEnd |
170 | - unset($this->enqueued[$handle]); |
|
170 | + unset($this->enqueued[ $handle ]); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return void |
184 | 184 | */ |
185 | - public function enqueueStyle($handle, $url, $deps = [], $version = null) |
|
185 | + public function enqueueStyle($handle, $url, $deps = [ ], $version = null) |
|
186 | 186 | { |
187 | 187 | // @codeCoverageIgnoreStart |
188 | 188 | if (function_exists('\wp_enqueue_style')) { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } |
192 | 192 | // @codeCoverageIgnoreEnd |
193 | 193 | |
194 | - $this->enqueued[$handle] = $url; |
|
194 | + $this->enqueued[ $handle ] = $url; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | { |
206 | 206 | $data = $this->enqueued; |
207 | 207 | |
208 | - if (null !== $handle && isset($this->enqueued[$handle])) { |
|
209 | - $data = $this->enqueued[$handle]; |
|
208 | + if (null !== $handle && isset($this->enqueued[ $handle ])) { |
|
209 | + $data = $this->enqueued[ $handle ]; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | return $data; |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | $candidates = $this->getCandidates(); |
233 | 233 | |
234 | 234 | // Bail and return original markup unmodified if we don't have things to do |
235 | - if (! $this->hasEnoughElements($candidates)) { |
|
235 | + if (!$this->hasEnoughElements($candidates)) { |
|
236 | 236 | return $markup; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Process what we found and modify original markup with our replacement |
240 | 240 | $fonts_array = $this->getFontsArray($candidates); |
241 | 241 | $font_markup = $this->buildFontsMarkup($fonts_array); |
242 | - $markup = $this->modifyMarkup($markup, $font_markup, $fonts_array['links']); |
|
242 | + $markup = $this->modifyMarkup($markup, $font_markup, $fonts_array[ 'links' ]); |
|
243 | 243 | |
244 | 244 | return $markup; |
245 | 245 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | protected function parseMarkupForHrefs($markup) |
255 | 255 | { |
256 | - $hrefs = []; |
|
256 | + $hrefs = [ ]; |
|
257 | 257 | |
258 | 258 | $dom = new \DOMDocument(); |
259 | 259 | // @codingStandardsIgnoreLine |
@@ -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,7 +441,7 @@ discard block |
||
441 | 441 | $html5 = $this->hasHtml5Doctype($content); |
442 | 442 | $xsl = $this->hasXslStylesheet($content); |
443 | 443 | |
444 | - return (($html || $html5) && ! $xsl); |
|
444 | + return (($html || $html5) && !$xsl); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | /** |
495 | 495 | * @param array $urls |
496 | 496 | */ |
497 | - public function setCandidates(array $urls = []) |
|
497 | + public function setCandidates(array $urls = [ ]) |
|
498 | 498 | { |
499 | 499 | $this->candidates = $urls; |
500 | 500 | } |
@@ -538,28 +538,28 @@ discard block |
||
538 | 538 | * |
539 | 539 | * @return null|string |
540 | 540 | */ |
541 | - public function buildGoogleFontsUrl(array $fonts, $subsets = []) |
|
541 | + public function buildGoogleFontsUrl(array $fonts, $subsets = [ ]) |
|
542 | 542 | { |
543 | 543 | $base_url = 'https://fonts.googleapis.com/css'; |
544 | - $font_args = []; |
|
545 | - $family = []; |
|
544 | + $font_args = [ ]; |
|
545 | + $family = [ ]; |
|
546 | 546 | |
547 | 547 | foreach ($fonts as $font_name => $font_weight) { |
548 | 548 | if (is_array($font_weight)) { |
549 | 549 | $font_weight = implode(',', $font_weight); |
550 | 550 | } |
551 | 551 | // Trimming end colon handles edge case of being given an empty $font_weight |
552 | - $family[] = trim(trim($font_name) . ':' . trim($font_weight), ':'); |
|
552 | + $family[ ] = trim(trim($font_name) . ':' . trim($font_weight), ':'); |
|
553 | 553 | } |
554 | 554 | |
555 | - $font_args['family'] = implode('|', $family); |
|
555 | + $font_args[ 'family' ] = implode('|', $family); |
|
556 | 556 | |
557 | - if (! empty($subsets)) { |
|
557 | + if (!empty($subsets)) { |
|
558 | 558 | if (is_array($subsets)) { |
559 | 559 | $subsets = array_unique($subsets); |
560 | 560 | $subsets = implode(',', $subsets); |
561 | 561 | } |
562 | - $font_args['subset'] = trim($subsets); |
|
562 | + $font_args[ 'subset' ] = trim($subsets); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | $url = $base_url . '?' . http_build_query($font_args); |
@@ -575,26 +575,26 @@ discard block |
||
575 | 575 | * |
576 | 576 | * @return array |
577 | 577 | */ |
578 | - protected function getFontsArray(array $candidates = []) |
|
578 | + protected function getFontsArray(array $candidates = [ ]) |
|
579 | 579 | { |
580 | - $fonts = []; |
|
580 | + $fonts = [ ]; |
|
581 | 581 | |
582 | 582 | foreach ($candidates as $candidate) { |
583 | - $fonts['links'][] = $candidate; |
|
583 | + $fonts[ 'links' ][ ] = $candidate; |
|
584 | 584 | |
585 | - $params = []; |
|
585 | + $params = [ ]; |
|
586 | 586 | parse_str(parse_url($candidate, PHP_URL_QUERY), $params); |
587 | 587 | |
588 | - if (isset($params['text'])) { |
|
588 | + if (isset($params[ 'text' ])) { |
|
589 | 589 | // Fonts with character limitations are segregated into |
590 | 590 | // under 'partial' (when `text` query param is used) |
591 | - $font_family = explode(':', $params['family']); |
|
592 | - $fonts['partial']['name'][] = $font_family[0]; |
|
593 | - $fonts['partial']['url'][] = $this->httpsify($candidate); |
|
591 | + $font_family = explode(':', $params[ 'family' ]); |
|
592 | + $fonts[ 'partial' ][ 'name' ][ ] = $font_family[ 0 ]; |
|
593 | + $fonts[ 'partial' ][ 'url' ][ ] = $this->httpsify($candidate); |
|
594 | 594 | } else { |
595 | 595 | $fontstrings = $this->buildFontStringsFromQueryParams($params); |
596 | 596 | foreach ($fontstrings as $font) { |
597 | - $fonts['complete'][] = $font; |
|
597 | + $fonts[ 'complete' ][ ] = $font; |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | } |
@@ -613,12 +613,12 @@ discard block |
||
613 | 613 | */ |
614 | 614 | protected function buildFontStringsFromQueryParams(array $params) |
615 | 615 | { |
616 | - $fonts = []; |
|
616 | + $fonts = [ ]; |
|
617 | 617 | |
618 | - foreach (explode('|', $params['family']) as $family) { |
|
618 | + foreach (explode('|', $params[ 'family' ]) as $family) { |
|
619 | 619 | $font = $this->parseFontStringFamilyParam($family, $params); |
620 | 620 | if (!empty($font)) { |
621 | - $fonts[] = $font; |
|
621 | + $fonts[ ] = $font; |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -631,12 +631,12 @@ discard block |
||
631 | 631 | $subset = false; |
632 | 632 | $family = explode(':', $family); |
633 | 633 | |
634 | - if (isset($params['subset'])) { |
|
634 | + if (isset($params[ 'subset' ])) { |
|
635 | 635 | // Use the found subset query parameter |
636 | - $subset = $params['subset']; |
|
637 | - } elseif (isset($family[2])) { |
|
636 | + $subset = $params[ 'subset' ]; |
|
637 | + } elseif (isset($family[ 2 ])) { |
|
638 | 638 | // Use the subset in the family string if present |
639 | - $subset = $family[2]; |
|
639 | + $subset = $family[ 2 ]; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | // We can have only the name specified in some cases |
@@ -656,19 +656,19 @@ discard block |
||
656 | 656 | */ |
657 | 657 | protected function buildFontStringParts(array $family, $subset = false) |
658 | 658 | { |
659 | - $parts = []; |
|
659 | + $parts = [ ]; |
|
660 | 660 | |
661 | 661 | // First part is the font name, which should always be present |
662 | - $parts[] = $family[0]; |
|
662 | + $parts[ ] = $family[ 0 ]; |
|
663 | 663 | |
664 | 664 | // Check if sizes are specified |
665 | - if (isset($family[1]) && strlen($family[1]) > 0) { |
|
666 | - $parts[] = $family[1]; |
|
665 | + if (isset($family[ 1 ]) && strlen($family[ 1 ]) > 0) { |
|
666 | + $parts[ ] = $family[ 1 ]; |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | // Add the subset if specified |
670 | 670 | if ($subset) { |
671 | - $parts[] = $subset; |
|
671 | + $parts[ ] = $subset; |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | return $parts; |
@@ -701,37 +701,37 @@ discard block |
||
701 | 701 | */ |
702 | 702 | protected function consolidateFontsArray(array $fonts_array) |
703 | 703 | { |
704 | - $fonts = []; |
|
705 | - $subsets = []; |
|
706 | - $fonts_to_subs = []; |
|
704 | + $fonts = [ ]; |
|
705 | + $subsets = [ ]; |
|
706 | + $fonts_to_subs = [ ]; |
|
707 | 707 | |
708 | - foreach ($fonts_array['complete'] as $font_string) { |
|
708 | + foreach ($fonts_array[ 'complete' ] as $font_string) { |
|
709 | 709 | $parts = explode(':', $font_string); |
710 | - $name = $parts[0]; |
|
711 | - $size = isset($parts[1]) ? $parts[1] : ''; |
|
710 | + $name = $parts[ 0 ]; |
|
711 | + $size = isset($parts[ 1 ]) ? $parts[ 1 ] : ''; |
|
712 | 712 | |
713 | - if (isset($fonts[$name])) { |
|
713 | + if (isset($fonts[ $name ])) { |
|
714 | 714 | // If a name already exists, append the new size |
715 | - $fonts[$name] .= ',' . $size; |
|
715 | + $fonts[ $name ] .= ',' . $size; |
|
716 | 716 | } else { |
717 | 717 | // Create a new key for the name and size |
718 | - $fonts[$name] = $size; |
|
718 | + $fonts[ $name ] = $size; |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | // Check if subset is specified as the third element |
722 | - if (isset($parts[2])) { |
|
723 | - $subset = $parts[2]; |
|
722 | + if (isset($parts[ 2 ])) { |
|
723 | + $subset = $parts[ 2 ]; |
|
724 | 724 | // Collect all the subsets defined into a single array |
725 | 725 | $elements = explode(',', $subset); |
726 | 726 | foreach ($elements as $sub) { |
727 | - $subsets[] = $sub; |
|
727 | + $subsets[ ] = $sub; |
|
728 | 728 | } |
729 | 729 | // Keeping a separate map of names => requested subsets for |
730 | 730 | // webfontloader purposes |
731 | - if (isset($fonts_to_subs[$name])) { |
|
732 | - $fonts_to_subs[$name] .= ',' . $subset; |
|
731 | + if (isset($fonts_to_subs[ $name ])) { |
|
732 | + $fonts_to_subs[ $name ] .= ',' . $subset; |
|
733 | 733 | } else { |
734 | - $fonts_to_subs[$name] = $subset; |
|
734 | + $fonts_to_subs[ $name ] = $subset; |
|
735 | 735 | } |
736 | 736 | } |
737 | 737 | } |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | // Sanitize and de-dup $fonts_to_subs mapping |
749 | 749 | $fonts_to_subs = $this->dedupValues($fonts_to_subs, false); // no sort |
750 | 750 | |
751 | - return [$fonts, $subsets, $fonts_to_subs]; |
|
751 | + return [ $fonts, $subsets, $fonts_to_subs ]; |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | /** |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | if (false !== $sort) { |
774 | 774 | sort($parts, (int) $sort); |
775 | 775 | } |
776 | - $data[$key] = $parts; |
|
776 | + $data[ $key ] = $parts; |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | return $data; |
@@ -853,9 +853,9 @@ discard block |
||
853 | 853 | $href = $this->encodeUnencodedAmpersands($font_url); |
854 | 854 | $markup = '<link rel="stylesheet" type="text/css" href="' . $href . '">'; |
855 | 855 | |
856 | - if (isset($fonts['partial'])) { |
|
857 | - if (is_array($fonts['partial']['url'])) { |
|
858 | - foreach ($fonts['partial']['url'] as $other) { |
|
856 | + if (isset($fonts[ 'partial' ])) { |
|
857 | + if (is_array($fonts[ 'partial' ][ 'url' ])) { |
|
858 | + foreach ($fonts[ 'partial' ][ 'url' ] as $other) { |
|
859 | 859 | $markup .= '<link rel="stylesheet" type="text/css"'; |
860 | 860 | $markup .= ' href="' . $this->encodeUnencodedAmpersands($other) . '">'; |
861 | 861 | } |
@@ -874,24 +874,24 @@ discard block |
||
874 | 874 | */ |
875 | 875 | protected function buildFontsMarkupScript(array $fonts) |
876 | 876 | { |
877 | - $families_array = []; |
|
877 | + $families_array = [ ]; |
|
878 | 878 | |
879 | 879 | list($names, $subsets, $mapping) = $this->consolidateFontsArray($fonts); |
880 | 880 | foreach ($names as $name => $sizes) { |
881 | 881 | $family = $name . ':' . implode(',', $sizes); |
882 | - if (isset($mapping[$name])) { |
|
883 | - $family .= ':' . implode(',', $mapping[$name]); |
|
882 | + if (isset($mapping[ $name ])) { |
|
883 | + $family .= ':' . implode(',', $mapping[ $name ]); |
|
884 | 884 | } |
885 | - $families_array[] = $family; |
|
885 | + $families_array[ ] = $family; |
|
886 | 886 | } |
887 | 887 | $families = "'" . implode("', '", $families_array) . "'"; |
888 | 888 | |
889 | 889 | // Load 'text' requests with the "custom" module |
890 | 890 | $custom = ''; |
891 | - if (isset($fonts['partial'])) { |
|
891 | + if (isset($fonts[ 'partial' ])) { |
|
892 | 892 | $custom = ",\n custom: {\n"; |
893 | - $custom .= " families: [ '" . implode("', '", $fonts['partial']['name']) . "' ],\n"; |
|
894 | - $custom .= " urls: [ '" . implode("', '", $fonts['partial']['url']) . "' ]\n"; |
|
893 | + $custom .= " families: [ '" . implode("', '", $fonts[ 'partial' ][ 'name' ]) . "' ],\n"; |
|
894 | + $custom .= " urls: [ '" . implode("', '", $fonts[ 'partial' ][ 'url' ]) . "' ]\n"; |
|
895 | 895 | $custom .= ' }'; |
896 | 896 | } |
897 | 897 |
@@ -910,7 +910,7 @@ |
||
910 | 910 | s.parentNode.insertBefore(wf, s); |
911 | 911 | })(); |
912 | 912 | </script> |
913 | -MARKUP; |
|
913 | +markup; |
|
914 | 914 | |
915 | 915 | return $markup; |
916 | 916 | } |