11<?php
2+ declare (strict_types = 1 );
23namespace hexydec \html ;
34
45class cssmin {
56
6- protected static $ tokens = Array (
7+ protected static $ tokens = [
78 'whitespace ' => '\s++ ' ,
89 'comment ' => '\\/ \\*[\d\D]*? \\* \\/ ' ,
910 'quotes ' => '(?<! \\\\)("(?:[^" \\\\]++| \\\\.)*+"| \'(?:[^ \'\\\\]++| \\\\.)*+ \') ' ,
@@ -19,9 +20,9 @@ class cssmin {
1920 'colon ' => ': ' ,
2021 'semicolon ' => '; ' ,
2122 'string ' => '!?[^\[\]{}\(\):;,>+=~\^$!"\/ \n\r\t]++ '
22- ) ;
23+ ] ;
2324
24- protected static $ config = Array (
25+ protected static $ config = [
2526 'removesemicolon ' => true ,
2627 'removezerounits ' => true ,
2728 'removeleadingzero ' => true ,
@@ -32,9 +33,9 @@ class cssmin {
3233 'email ' => false ,
3334 'maxline ' => false ,
3435 'output ' => 'minify '
35- ) ;
36+ ] ;
3637
37- public static function minify (string $ code , array $ config = Array ()) {
38+ public static function minify (string $ code , array $ config = []) : string {
3839 $ config = array_merge (self ::$ config , $ config );
3940
4041 // set email options
@@ -66,12 +67,12 @@ public static function minify(string $code, array $config = Array()) {
6667 }
6768
6869 protected static function parse (array &$ tokens ) {
69- $ rules = Array () ;
70+ $ rules = [] ;
7071 $ select = true ;
7172 $ comment = null ;
7273 $ media = false ;
73- $ selectors = Array () ;
74- $ properties = Array () ;
74+ $ selectors = [] ;
75+ $ properties = [] ;
7576 $ token = current ($ tokens );
7677 do {
7778
@@ -84,11 +85,11 @@ protected static function parse(array &$tokens) {
8485 return $ rules ;
8586 } elseif (in_array ($ token ['type ' ], ['string ' , 'colon ' ])) {
8687 if ($ token ['value ' ] == '@media ' ) {
87- $ rules [] = Array (
88+ $ rules [] = [
8889 'media ' => self ::parseMediaQuery ($ tokens ),
8990 'rules ' => self ::parse ($ tokens ),
9091 'comment ' => $ comment
91- ) ;
92+ ] ;
9293 $ comment = false ;
9394 } else {
9495 // prev($tokens);
@@ -106,28 +107,28 @@ protected static function parse(array &$tokens) {
106107 while (($ token = next ($ tokens )) !== false ) {
107108 if ($ token ['type ' ] == 'colon ' ) {
108109 $ important = false ;
109- $ properties [] = Array (
110+ $ properties [] = [
110111 'property ' => $ prop ,
111112 'value ' => self ::parsePropertyValue ($ tokens , $ important , $ propcomment ),
112113 'important ' => $ important ,
113114 'semicolon ' => '; ' ,
114115 'comment ' => $ propcomment
115- ) ;
116+ ] ;
116117 break ;
117118 }
118119 }
119120
120121 // end rule
121122 } elseif ($ token ['type ' ] == 'curlyclose ' ) {
122123 if ($ selectors && $ properties ) {
123- $ rules [] = Array (
124+ $ rules [] = [
124125 'selectors ' => $ selectors ,
125126 'properties ' => $ properties ,
126127 'comment ' => $ comment
127- ) ;
128+ ] ;
128129 }
129- $ selectors = Array () ;
130- $ properties = Array () ;
130+ $ selectors = [] ;
131+ $ properties = [] ;
131132 $ select = true ;
132133 $ comment = false ;
133134 }
@@ -136,13 +137,13 @@ protected static function parse(array &$tokens) {
136137 }
137138
138139 protected static function parseMediaQuery (array &$ tokens ) {
139- $ media = Array () ;
140- $ default = $ rule = Array (
140+ $ media = [] ;
141+ $ default = $ rule = [
141142 'media ' => false ,
142143 'only ' => false ,
143144 'not ' => false ,
144- 'properties ' => Array ()
145- ) ;
145+ 'properties ' => []
146+ ] ;
146147 while (($ token = next ($ tokens )) !== false ) {
147148 switch ($ token ['type ' ]) {
148149 case 'string ' :
@@ -197,7 +198,7 @@ protected static function parseMediaQuery(array &$tokens) {
197198 }
198199
199200 protected static function parseSelectors (array &$ tokens ) {
200- $ selector = Array () ;
201+ $ selector = [] ;
201202 $ join = false ;
202203 $ token = current ($ tokens );
203204 do {
@@ -208,10 +209,10 @@ protected static function parseSelectors(array &$tokens) {
208209 }
209210 break ;
210211 case 'string ' :
211- $ selector [] = Array (
212+ $ selector [] = [
212213 'selector ' => $ token ['value ' ],
213214 'join ' => $ join
214- ) ;
215+ ] ;
215216 $ join = false ;
216217 break ;
217218 case 'colon ' :
@@ -230,7 +231,7 @@ protected static function parseSelectors(array &$tokens) {
230231 }
231232
232233 // capture selector
233- } elseif (!in_array ($ token ['type ' ], Array ( 'whitespace ' , 'comma ' , 'curlyopen ' ) )) {
234+ } elseif (!in_array ($ token ['type ' ], [ 'whitespace ' , 'comma ' , 'curlyopen ' ] )) {
234235 $ parts .= $ token ['value ' ];
235236
236237 // stop here
@@ -241,10 +242,10 @@ protected static function parseSelectors(array &$tokens) {
241242 }
242243
243244 // save selector
244- $ selector [] = Array (
245+ $ selector [] = [
245246 'selector ' => $ parts ,
246247 'join ' => $ join
247- ) ;
248+ ] ;
248249 $ join = false ;
249250 break ;
250251 case 'squareopen ' :
@@ -259,10 +260,10 @@ protected static function parseSelectors(array &$tokens) {
259260 }
260261 }
261262 }
262- $ selector [] = Array (
263+ $ selector [] = [
263264 'selector ' => '[ ' .$ parts .'] ' ,
264265 'join ' => $ join
265- ) ;
266+ ] ;
266267 $ join = false ;
267268 break ;
268269 case 'curlyopen ' :
@@ -277,19 +278,19 @@ protected static function parseSelectors(array &$tokens) {
277278 }
278279
279280 protected static function parsePropertyValue (array &$ tokens , bool &$ important = false , string &$ comment = null ) {
280- $ properties = Array () ;
281- $ values = Array () ;
281+ $ properties = [] ;
282+ $ values = [] ;
282283 $ important = false ;
283284 $ comment = null ;
284285 while (($ token = next ($ tokens )) !== false ) {
285286 if ($ token ['type ' ] == 'comma ' ) {
286287 $ properties [] = $ values ;
287- $ values = Array () ;
288+ $ values = [] ;
288289 } elseif ($ token ['value ' ] == '!important ' ) {
289290 $ important = true ;
290291 } elseif ($ token ['type ' ] == 'bracketopen ' ) {
291292 $ values [] = self ::parsePropertyValue ($ tokens );
292- } elseif (in_array ($ token ['type ' ], Array ( 'semicolon ' , 'bracketclose ' ) )) {
293+ } elseif (in_array ($ token ['type ' ], [ 'semicolon ' , 'bracketclose ' ] )) {
293294 while (($ token = next ($ tokens )) !== false ) {
294295 if ($ token ['type ' ] == 'comment ' ) {
295296 $ comment = $ token ['value ' ];
@@ -460,8 +461,8 @@ protected static function compile(array $ast, array $config, int $indent = 0) {
460461 return rtrim ($ css );
461462 }
462463
463- protected static function compileProperty (array $ value , int $ b , string $ join = ' ' ) {
464- $ properties = Array () ;
464+ protected static function compileProperty (array $ value , bool $ b = false , string $ join = ' ' ) {
465+ $ properties = [] ;
465466 foreach ($ value AS $ group ) {
466467 $ compiled = '' ;
467468 foreach ($ group AS $ item ) {
0 commit comments