@@ -7,22 +7,22 @@ discard block |
||
| 7 | 7 | class GoogleFontsCollection |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - protected $links = []; |
|
| 10 | + protected $links = [ ]; |
|
| 11 | 11 | |
| 12 | - protected $texts = []; |
|
| 12 | + protected $texts = [ ]; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * @var array|ZWF\GoogleFont[] |
| 16 | 16 | */ |
| 17 | - protected $fonts = []; |
|
| 17 | + protected $fonts = [ ]; |
|
| 18 | 18 | |
| 19 | - protected $subsetsMap = []; |
|
| 19 | + protected $subsetsMap = [ ]; |
|
| 20 | 20 | |
| 21 | - protected $namedSizes = []; |
|
| 21 | + protected $namedSizes = [ ]; |
|
| 22 | 22 | |
| 23 | - public function __construct(array $urls = []) |
|
| 23 | + public function __construct(array $urls = [ ]) |
|
| 24 | 24 | { |
| 25 | - if (! empty($urls)) { |
|
| 25 | + if (!empty($urls)) { |
|
| 26 | 26 | foreach ($urls as $url) { |
| 27 | 27 | $this->add($url); |
| 28 | 28 | } |
@@ -33,24 +33,24 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $this->addLink($url); |
| 35 | 35 | |
| 36 | - $params = []; |
|
| 36 | + $params = [ ]; |
|
| 37 | 37 | parse_str(parse_url($url, PHP_URL_QUERY), $params); |
| 38 | 38 | |
| 39 | - $bucket = isset($params['text']) ? 'text' : 'complete'; |
|
| 39 | + $bucket = isset($params[ 'text' ]) ? 'text' : 'complete'; |
|
| 40 | 40 | |
| 41 | 41 | $fontstrings = $this->buildFontStringsFromQueryParams($params); |
| 42 | 42 | foreach ($fontstrings as $font) { |
| 43 | 43 | $this->addFontFromString($font, $bucket); |
| 44 | 44 | if ('text' === $bucket) { |
| 45 | 45 | $font_family = explode(':', $font); |
| 46 | - $this->addTextFont($font_family[0], Utils::httpsify($url)); |
|
| 46 | + $this->addTextFont($font_family[ 0 ], Utils::httpsify($url)); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | protected function addLink($url) |
| 52 | 52 | { |
| 53 | - $this->links[] = $url; |
|
| 53 | + $this->links[ ] = $url; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | protected function addFontFromString($fontstring, $bucket = 'complete') |
@@ -60,15 +60,15 @@ discard block |
||
| 60 | 60 | $subsets = $font->getSubsetsString(); |
| 61 | 61 | |
| 62 | 62 | // Add to bucket list |
| 63 | - $this->fonts[$bucket][] = $font; |
|
| 63 | + $this->fonts[ $bucket ][ ] = $font; |
|
| 64 | 64 | |
| 65 | 65 | // Keeping a separate map of names => subsets for webfontloader purposes |
| 66 | - if (! array_key_exists($name, $this->subsetsMap)) { |
|
| 66 | + if (!array_key_exists($name, $this->subsetsMap)) { |
|
| 67 | 67 | // Nothing found yet, create a new key |
| 68 | - $this->subsetsMap[$name] = $subsets; |
|
| 68 | + $this->subsetsMap[ $name ] = $subsets; |
|
| 69 | 69 | } else { |
| 70 | 70 | // Something is in there already, merge |
| 71 | - $this->subsetsMap[$name] = array_merge($this->subsetsMap[$name], (array) $subsets); |
|
| 71 | + $this->subsetsMap[ $name ] = array_merge($this->subsetsMap[ $name ], (array) $subsets); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Deduplicate values and don't sort the subsets map |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | protected function addTextFont($name, $url) |
| 82 | 82 | { |
| 83 | - $this->texts['name'][] = $name; |
|
| 84 | - $this->texts['url'][] = $url; |
|
| 83 | + $this->texts[ 'name' ][ ] = $name; |
|
| 84 | + $this->texts[ 'url' ][ ] = $url; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function hasText() |
| 119 | 119 | { |
| 120 | - return (! empty($this->texts)); |
|
| 120 | + return (!empty($this->texts)); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function getTextUrls() |
| 127 | 127 | { |
| 128 | - $urls = []; |
|
| 128 | + $urls = [ ]; |
|
| 129 | 129 | |
| 130 | 130 | if ($this->hasText()) { |
| 131 | - $urls = $this->texts['url']; |
|
| 131 | + $urls = $this->texts[ 'url' ]; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | return $urls; |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function getTextNames() |
| 141 | 141 | { |
| 142 | - return $this->texts['name']; |
|
| 142 | + return $this->texts[ 'name' ]; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function getFonts() |
| 149 | 149 | { |
| 150 | - return $this->fonts['complete']; |
|
| 150 | + return $this->fonts[ 'complete' ]; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -166,11 +166,11 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function getSubsets() |
| 168 | 168 | { |
| 169 | - $subsets = []; |
|
| 169 | + $subsets = [ ]; |
|
| 170 | 170 | |
| 171 | 171 | $fonts = $this->getFonts(); |
| 172 | 172 | foreach ($fonts as $font) { |
| 173 | - $subsets[] = $font->getSubsets(); |
|
| 173 | + $subsets[ ] = $font->getSubsets(); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | $subsets = Utils::arrayFlattenIterative($subsets); |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | protected function buildNamedsizesMap() |
| 185 | 185 | { |
| 186 | - $fonts = []; |
|
| 186 | + $fonts = [ ]; |
|
| 187 | 187 | |
| 188 | 188 | foreach ($this->getFonts() as $font) { |
| 189 | 189 | $name = $font->getName(); |
| 190 | - if (! array_key_exists($name, $fonts)) { |
|
| 191 | - $fonts[$name] = $font->getSizes(); |
|
| 190 | + if (!array_key_exists($name, $fonts)) { |
|
| 191 | + $fonts[ $name ] = $font->getSizes(); |
|
| 192 | 192 | } else { |
| 193 | - $fonts[$name] = array_merge($fonts[$name], $font->getSizes()); |
|
| 193 | + $fonts[ $name ] = array_merge($fonts[ $name ], $font->getSizes()); |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
@@ -213,12 +213,12 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | protected function buildFontStringsFromQueryParams(array $params) |
| 215 | 215 | { |
| 216 | - $fonts = []; |
|
| 216 | + $fonts = [ ]; |
|
| 217 | 217 | |
| 218 | - foreach (explode('|', $params['family']) as $family) { |
|
| 218 | + foreach (explode('|', $params[ 'family' ]) as $family) { |
|
| 219 | 219 | $font = $this->parseFontStringName($family, $params); |
| 220 | - if (! empty($font)) { |
|
| 221 | - $fonts[] = $font; |
|
| 220 | + if (!empty($font)) { |
|
| 221 | + $fonts[ ] = $font; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | $subset = false; |
| 237 | 237 | $family = explode(':', $family); |
| 238 | 238 | |
| 239 | - if (isset($params['subset'])) { |
|
| 239 | + if (isset($params[ 'subset' ])) { |
|
| 240 | 240 | // Use the found subset query parameter |
| 241 | - $subset = $params['subset']; |
|
| 242 | - } elseif (isset($family[2])) { |
|
| 241 | + $subset = $params[ 'subset' ]; |
|
| 242 | + } elseif (isset($family[ 2 ])) { |
|
| 243 | 243 | // Use the subset in the family string if present |
| 244 | - $subset = $family[2]; |
|
| 244 | + $subset = $family[ 2 ]; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // $family can have a lot of thing specified with separators etc. |
@@ -261,19 +261,19 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | protected function validateFontStringParts(array $family, $subset = false) |
| 263 | 263 | { |
| 264 | - $parts = []; |
|
| 264 | + $parts = [ ]; |
|
| 265 | 265 | |
| 266 | 266 | // First part is the font name, which should always be present |
| 267 | - $parts[] = $family[0]; |
|
| 267 | + $parts[ ] = $family[ 0 ]; |
|
| 268 | 268 | |
| 269 | 269 | // Check if sizes are specified |
| 270 | - if (isset($family[1]) && strlen($family[1]) > 0) { |
|
| 271 | - $parts[] = $family[1]; |
|
| 270 | + if (isset($family[ 1 ]) && strlen($family[ 1 ]) > 0) { |
|
| 271 | + $parts[ ] = $family[ 1 ]; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Add the subset if specified |
| 275 | 275 | if ($subset) { |
| 276 | - $parts[] = $subset; |
|
| 276 | + $parts[ ] = $subset; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | return $parts; |
@@ -7,11 +7,11 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | protected $name = ''; |
| 9 | 9 | |
| 10 | - protected $sizes = []; |
|
| 10 | + protected $sizes = [ ]; |
|
| 11 | 11 | |
| 12 | - protected $subsets = []; |
|
| 12 | + protected $subsets = [ ]; |
|
| 13 | 13 | |
| 14 | - public function __construct($name, array $sizes = [], array $subsets = []) |
|
| 14 | + public function __construct($name, array $sizes = [ ], array $subsets = [ ]) |
|
| 15 | 15 | { |
| 16 | 16 | $this->setName($name); |
| 17 | 17 | $this->setSizes($sizes); |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | $sizes = $this->getSizesString(); |
| 85 | 85 | $subsets = $this->getSubsetsString(); |
| 86 | 86 | |
| 87 | - if (! empty($sizes)) { |
|
| 88 | - $parts[] = $sizes; |
|
| 87 | + if (!empty($sizes)) { |
|
| 88 | + $parts[ ] = $sizes; |
|
| 89 | 89 | } |
| 90 | - if (! empty($subsets)) { |
|
| 91 | - $parts[] = $subsets; |
|
| 90 | + if (!empty($subsets)) { |
|
| 91 | + $parts[ ] = $subsets; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return implode(':', $parts); |
@@ -124,14 +124,14 @@ discard block |
||
| 124 | 124 | public static function fromString($fontstring) |
| 125 | 125 | { |
| 126 | 126 | $parts = explode(':', $fontstring); |
| 127 | - $font = new self($parts[0]); |
|
| 127 | + $font = new self($parts[ 0 ]); |
|
| 128 | 128 | |
| 129 | - if (isset($parts[1])) { |
|
| 130 | - $font->setSizes($parts[1]); |
|
| 129 | + if (isset($parts[ 1 ])) { |
|
| 130 | + $font->setSizes($parts[ 1 ]); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if (isset($parts[2])) { |
|
| 134 | - $font->setSubsets($parts[2]); |
|
| 133 | + if (isset($parts[ 2 ])) { |
|
| 134 | + $font->setSubsets($parts[ 2 ]); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | return $font; |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | const FILTER_OB_CLEANER = 'zwf_gfo_clean_ob'; |
| 17 | 17 | const DEFAULT_OB_CLEANER = false; |
| 18 | 18 | |
| 19 | - protected $candidates = []; |
|
| 19 | + protected $candidates = [ ]; |
|
| 20 | 20 | |
| 21 | - protected $enqueued = []; |
|
| 21 | + protected $enqueued = [ ]; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * @param array $urls |
| 25 | 25 | */ |
| 26 | - public function setCandidates(array $urls = []) |
|
| 26 | + public function setCandidates(array $urls = [ ]) |
|
| 27 | 27 | { |
| 28 | 28 | $this->candidates = $urls; |
| 29 | 29 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * Scan and optimize requests found in the markup (uses more |
| 53 | 53 | * memory but works on [almost] any theme) |
| 54 | 54 | */ |
| 55 | - add_action('template_redirect', [$this, 'startBuffering'], 11); |
|
| 55 | + add_action('template_redirect', [ $this, 'startBuffering' ], 11); |
|
| 56 | 56 | break; |
| 57 | 57 | |
| 58 | 58 | case self::DEFAULT_OPERATION_MODE: |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * Scan only things added via wp_enqueue_style (uses slightly |
| 62 | 62 | * less memory usually, but requires a decently coded theme) |
| 63 | 63 | */ |
| 64 | - add_filter('print_styles_array', [$this, 'processStylesHandles']); |
|
| 64 | + add_filter('print_styles_array', [ $this, 'processStylesHandles' ]); |
|
| 65 | 65 | break; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $candidate_handles = $this->findCandidateHandles($handles); |
| 84 | 84 | |
| 85 | 85 | // Bail if we don't have anything that makes sense for us to continue |
| 86 | - if (! $this->hasEnoughElements($candidate_handles)) { |
|
| 86 | + if (!$this->hasEnoughElements($candidate_handles)) { |
|
| 87 | 87 | return $handles; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | $font_url = $collection->getCombinedUrl(); |
| 98 | 98 | $handle_name = 'zwf-gfo-combined'; |
| 99 | 99 | $this->enqueueStyle($handle_name, $font_url); |
| 100 | - $handles[] = $handle_name; |
|
| 100 | + $handles[ ] = $handle_name; |
|
| 101 | 101 | |
| 102 | 102 | // Process 'text-only' requests if there are any... |
| 103 | 103 | $texts = $collection->getTextUrls(); |
| 104 | 104 | foreach ($texts as $k => $url) { |
| 105 | 105 | $handle_name = 'zwf-gfo-combined-txt-' . ($k + 1); |
| 106 | 106 | $this->enqueueStyle($handle_name, $url); |
| 107 | - $handles[] = $handle_name; |
|
| 107 | + $handles[ ] = $handle_name; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Remove/dequeue the ones we just combined above |
@@ -131,14 +131,14 @@ discard block |
||
| 131 | 131 | protected function findCandidateHandles(array $handles) |
| 132 | 132 | { |
| 133 | 133 | $handler = /** @scrutinizer ignore-call */ \wp_styles(); |
| 134 | - $candidate_handles = []; |
|
| 134 | + $candidate_handles = [ ]; |
|
| 135 | 135 | |
| 136 | 136 | foreach ($handles as $handle) { |
| 137 | 137 | $dep = $handler->query($handle, 'registered'); |
| 138 | 138 | if ($dep) { |
| 139 | 139 | $url = $dep->src; |
| 140 | 140 | if (Utils::isGoogleWebFontUrl($url)) { |
| 141 | - $candidate_handles[$handle] = $url; |
|
| 141 | + $candidate_handles[ $handle ] = $url; |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | - protected function hasEnoughElements(array $candidates = []) |
|
| 156 | + protected function hasEnoughElements(array $candidates = [ ]) |
|
| 157 | 157 | { |
| 158 | 158 | $enough = true; |
| 159 | 159 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | \wp_dequeue_style($handle); |
| 185 | 185 | } |
| 186 | 186 | // @codeCoverageIgnoreEnd |
| 187 | - unset($this->enqueued[$handle]); |
|
| 187 | + unset($this->enqueued[ $handle ]); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return void |
| 201 | 201 | */ |
| 202 | - protected function enqueueStyle($handle, $url, $deps = [], $version = null) |
|
| 202 | + protected function enqueueStyle($handle, $url, $deps = [ ], $version = null) |
|
| 203 | 203 | { |
| 204 | 204 | // @codeCoverageIgnoreStart |
| 205 | 205 | if (function_exists('\wp_enqueue_style')) { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | // @codeCoverageIgnoreEnd |
| 210 | 210 | |
| 211 | - $this->enqueued[$handle] = $url; |
|
| 211 | + $this->enqueued[ $handle ] = $url; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -222,8 +222,8 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $data = $this->enqueued; |
| 224 | 224 | |
| 225 | - if (null !== $handle && isset($this->enqueued[$handle])) { |
|
| 226 | - $data = $this->enqueued[$handle]; |
|
| 225 | + if (null !== $handle && isset($this->enqueued[ $handle ])) { |
|
| 226 | + $data = $this->enqueued[ $handle ]; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | return $data; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | public function processMarkup($markup) |
| 242 | 242 | { |
| 243 | 243 | $hrefs = $this->parseMarkupForHrefs($markup); |
| 244 | - if (! empty($hrefs)) { |
|
| 244 | + if (!empty($hrefs)) { |
|
| 245 | 245 | $this->setCandidates($hrefs); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $candidates = $this->getCandidates(); |
| 250 | 250 | |
| 251 | 251 | // Bail and return original markup unmodified if we don't have things to do |
| 252 | - if (! $this->hasEnoughElements($candidates)) { |
|
| 252 | + if (!$this->hasEnoughElements($candidates)) { |
|
| 253 | 253 | return $markup; |
| 254 | 254 | } |
| 255 | 255 | |
@@ -291,11 +291,11 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | protected function filterHrefsFromCandidateLinkNodes(\DOMNodeList $nodes) |
| 293 | 293 | { |
| 294 | - $hrefs = []; |
|
| 294 | + $hrefs = [ ]; |
|
| 295 | 295 | |
| 296 | 296 | foreach ($nodes as $node) { |
| 297 | 297 | if ($this->isCandidateLink($node)) { |
| 298 | - $hrefs[] = $node->getAttribute('href'); |
|
| 298 | + $hrefs[ ] = $node->getAttribute('href'); |
|
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | |
| 368 | 368 | // Start our own buffering |
| 369 | - $started = ob_start([$this, 'endBuffering']); |
|
| 369 | + $started = ob_start([ $this, 'endBuffering' ]); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | return $started; |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | public function endBuffering($markup) |
| 376 | 376 | { |
| 377 | 377 | // Bail early on things we don't want to parse |
| 378 | - if (! $this->isMarkupDoable($markup)) { |
|
| 378 | + if (!$this->isMarkupDoable($markup)) { |
|
| 379 | 379 | return $markup; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | $html5 = Utils::hasHtml5Doctype($content); |
| 461 | 461 | $xsl = Utils::hasXslStylesheet($content); |
| 462 | 462 | |
| 463 | - return (($html || $html5) && ! $xsl); |
|
| 463 | + return (($html || $html5) && !$xsl); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |