@@ -66,7 +66,7 @@ public function __get(string $var) {
66
66
if ($ var == 'config ' ) {
67
67
return $ this ->config ;
68
68
} elseif ($ var == 'length ' ) {
69
- return count ($ this ->children );
69
+ return \ count ($ this ->children );
70
70
}
71
71
return null ;
72
72
}
@@ -87,7 +87,7 @@ public function toArray() : array {
87
87
* @param mixed $value The value of the array key in the children array to be updated
88
88
*/
89
89
public function offsetSet ($ i , $ value ) : void {
90
- if (is_null ($ i )) $ this ->children [] = $ value ;
90
+ if (\ is_null ($ i )) $ this ->children [] = $ value ;
91
91
else $ this ->children [$ i ] = $ value ;
92
92
}
93
93
@@ -176,23 +176,23 @@ public function valid() : bool {
176
176
public function open (string $ url , $ context = null , string &$ error = null ) {
177
177
178
178
// open a handle to the stream
179
- if (($ handle = @fopen ($ url , 'rb ' , false , $ context )) === false ) {
179
+ if (($ handle = @\ fopen ($ url , 'rb ' , false , $ context )) === false ) {
180
180
$ error = 'Could not open file " ' .$ url .'" ' ;
181
181
182
182
// retrieve the stream contents
183
- } elseif (($ html = stream_get_contents ($ handle )) === false ) {
183
+ } elseif (($ html = \ stream_get_contents ($ handle )) === false ) {
184
184
$ error = 'Could not read file " ' .$ url .'" ' ;
185
185
186
186
// success
187
187
} else {
188
188
189
189
// find charset in headers
190
190
$ charset = null ;
191
- $ meta = stream_get_meta_data ($ handle );
191
+ $ meta = \ stream_get_meta_data ($ handle );
192
192
if (!empty ($ meta ['wrapper_data ' ])) {
193
193
foreach ($ meta ['wrapper_data ' ] AS $ item ) {
194
- if (mb_stripos ($ item , 'Content-Type: ' ) === 0 && ($ charset = mb_stristr ($ item , 'charset= ' )) !== false ) {
195
- $ charset = mb_substr ($ charset , 8 );
194
+ if (\ mb_stripos ($ item , 'Content-Type: ' ) === 0 && ($ charset = \ mb_stristr ($ item , 'charset= ' )) !== false ) {
195
+ $ charset = \ mb_substr ($ charset , 8 );
196
196
break ;
197
197
}
198
198
}
@@ -218,7 +218,7 @@ public function load(string $html, string $charset = null, &$error = null) : boo
218
218
219
219
// detect the charset
220
220
if ($ charset || ($ charset = $ this ->getCharsetFromHtml ($ html )) !== null ) {
221
- $ html = mb_convert_encoding ($ html , mb_internal_encoding (), $ charset );
221
+ $ html = \ mb_convert_encoding ($ html , \ mb_internal_encoding (), $ charset );
222
222
}
223
223
224
224
// reset the document
@@ -246,20 +246,20 @@ public function load(string $html, string $charset = null, &$error = null) : boo
246
246
* @return string The defined or detected charset or null if the charset is not defined
247
247
*/
248
248
protected function getCharsetFromHtml (string $ html ) : ?string {
249
- if (preg_match ('/<meta[^>]+charset[^>]+>/i ' , $ html , $ match )) {
249
+ if (\ preg_match ('/<meta[^>]+charset[^>]+>/i ' , $ html , $ match )) {
250
250
$ obj = new htmldoc ($ this ->config );
251
- if ($ obj ->load ($ match [0 ], mb_internal_encoding ())) {
251
+ if ($ obj ->load ($ match [0 ], \ mb_internal_encoding ())) {
252
252
253
253
// <meta charset="xxx" />
254
254
if (($ value = $ obj ->attr ('charset ' )) !== null ) {
255
255
return $ value ;
256
256
257
257
// <meta http-equiv="Content-Type" content="text/html; charset=xxx" />
258
- } elseif (($ value = $ obj ->eq (0 )->attr ('content ' )) !== null && ($ charset = mb_stristr ($ value , 'charset= ' )) !== false ) {
259
- return mb_substr ($ charset , 8 );
258
+ } elseif (($ value = $ obj ->eq (0 )->attr ('content ' )) !== null && ($ charset = \ mb_stristr ($ value , 'charset= ' )) !== false ) {
259
+ return \ mb_substr ($ charset , 8 );
260
260
}
261
261
}
262
- } elseif (($ charset = mb_detect_encoding ($ html )) !== false ) {
262
+ } elseif (($ charset = \ mb_detect_encoding ($ html )) !== false ) {
263
263
return $ charset ;
264
264
}
265
265
return null ;
@@ -284,7 +284,7 @@ protected function parse(tokenise $tokens) : bool {
284
284
* @return array An array of selector components
285
285
*/
286
286
protected function parseSelector (string $ selector ) {
287
- $ selector = trim ($ selector );
287
+ $ selector = \ trim ($ selector );
288
288
$ tokens = new tokenise (self ::$ selectors , $ selector );
289
289
if (($ token = $ tokens ->next ()) !== null ) {
290
290
$ selectors = $ parts = [];
@@ -293,15 +293,15 @@ protected function parseSelector(string $selector) {
293
293
switch ($ token ['type ' ]) {
294
294
case 'id ' :
295
295
$ parts [] = [
296
- 'id ' => mb_substr ($ token ['value ' ], 1 ),
296
+ 'id ' => \ mb_substr ($ token ['value ' ], 1 ),
297
297
'join ' => $ join
298
298
];
299
299
$ join = null ;
300
300
break ;
301
301
302
302
case 'class ' :
303
303
$ parts [] = [
304
- 'class ' => mb_substr ($ token ['value ' ], 1 ),
304
+ 'class ' => \ mb_substr ($ token ['value ' ], 1 ),
305
305
'join ' => $ join
306
306
];
307
307
$ join = null ;
@@ -320,9 +320,9 @@ protected function parseSelector(string $selector) {
320
320
while (($ token = $ tokens ->next ()) !== false ) {
321
321
if ($ token ['type ' ] === 'squareclose ' ) {
322
322
break ;
323
- } elseif (in_array ($ token ['type ' ], ['string ' , 'quotes ' ])) {
323
+ } elseif (\ in_array ($ token ['type ' ], ['string ' , 'quotes ' ])) {
324
324
if ($ token ['type ' ] == 'quotes ' ) {
325
- $ token ['value ' ] = stripslashes (mb_substr ($ token ['value ' ], 1 , -1 ));
325
+ $ token ['value ' ] = \ stripslashes (\ mb_substr ($ token ['value ' ], 1 , -1 ));
326
326
}
327
327
$ item [isset ($ item ['attribute ' ]) ? 'value ' : 'attribute ' ] = $ token ['value ' ];
328
328
} elseif ($ token ['type ' ] === 'comparison ' ) {
@@ -335,14 +335,14 @@ protected function parseSelector(string $selector) {
335
335
336
336
case 'pseudo ' :
337
337
$ parts [] = [
338
- 'pseudo ' => mb_substr ($ token ['value ' ], 1 ),
338
+ 'pseudo ' => \ mb_substr ($ token ['value ' ], 1 ),
339
339
'join ' => $ join
340
340
];
341
341
$ join = null ;
342
342
break ;
343
343
344
344
case 'join ' :
345
- $ join = trim ($ token ['value ' ]);
345
+ $ join = \ trim ($ token ['value ' ]);
346
346
break ;
347
347
348
348
case 'whitespace ' :
@@ -400,7 +400,7 @@ public function get(int $index = null) {
400
400
// build children that are tags
401
401
$ children = [];
402
402
foreach ($ this ->children AS $ item ) {
403
- if (get_class ($ item ) === 'hexydec \\html \\tag ' ) {
403
+ if (\ get_class ($ item ) === 'hexydec \\html \\tag ' ) {
404
404
$ children [] = $ item ;
405
405
}
406
406
}
@@ -412,7 +412,7 @@ public function get(int $index = null) {
412
412
413
413
// check if index is minus
414
414
if ($ index < 0 ) {
415
- $ index = count ($ children ) + $ index ;
415
+ $ index = \ count ($ children ) + $ index ;
416
416
}
417
417
418
418
// return index if set
@@ -432,12 +432,12 @@ public function find(string $selector) : htmldoc {
432
432
$ found = [];
433
433
434
434
// parse selector and find tags
435
- if (is_array ($ selector ) || ($ selector = $ this ->parseSelector ($ selector )) !== false ) {
435
+ if (\ is_array ($ selector ) || ($ selector = $ this ->parseSelector ($ selector )) !== false ) {
436
436
foreach ($ this ->children AS $ item ) {
437
- if (get_class ($ item ) === 'hexydec \\html \\tag ' ) {
437
+ if (\ get_class ($ item ) === 'hexydec \\html \\tag ' ) {
438
438
foreach ($ selector AS $ value ) {
439
439
if (($ items = $ item ->find ($ value )) !== false ) {
440
- $ found = array_merge ($ found , $ items );
440
+ $ found = \ array_merge ($ found , $ items );
441
441
}
442
442
}
443
443
}
@@ -479,7 +479,7 @@ public function last() : htmldoc {
479
479
public function eq (int $ index ) : htmldoc {
480
480
$ doc = new htmldoc ($ this ->config );
481
481
if ($ index < 0 ) {
482
- $ index = count ($ this ->children ) + $ index ;
482
+ $ index = \ count ($ this ->children ) + $ index ;
483
483
}
484
484
if (isset ($ this ->children [$ index ])) {
485
485
$ doc ->collection ([$ this ->children [$ index ]]);
@@ -504,7 +504,7 @@ public function children() : htmldoc {
504
504
*/
505
505
public function attr (string $ key ) : ?string {
506
506
foreach ($ this ->children AS $ item ) {
507
- if (get_class ($ item ) === 'hexydec \\html \\tag ' ) {
507
+ if (\ get_class ($ item ) === 'hexydec \\html \\tag ' ) {
508
508
return $ item ->attr ($ key );
509
509
}
510
510
}
@@ -521,12 +521,12 @@ public function text() : string {
521
521
foreach ($ this ->children AS $ item ) {
522
522
523
523
// only get text from these objects
524
- if (in_array (get_class ($ item ), ['hexydec \\html \\tag ' , 'hexydec \\html \\text ' ], true )) {
524
+ if (\ in_array (\ get_class ($ item ), ['hexydec \\html \\tag ' , 'hexydec \\html \\text ' ], true )) {
525
525
$ value = $ item ->text ();
526
- $ text = array_merge ($ text , is_array ($ value ) ? $ value : [$ value ]);
526
+ $ text = \ array_merge ($ text , \ is_array ($ value ) ? $ value : [$ value ]);
527
527
}
528
528
}
529
- return implode (' ' , $ text );
529
+ return \ implode (' ' , $ text );
530
530
}
531
531
532
532
/**
@@ -548,7 +548,7 @@ protected function collection(array $nodes) : void {
548
548
public function minify (array $ minify = []) : void {
549
549
550
550
// merge config
551
- $ minify = array_replace_recursive ($ this ->config ['minify ' ], $ minify );
551
+ $ minify = \ array_replace_recursive ($ this ->config ['minify ' ], $ minify );
552
552
553
553
// set minify output parameters
554
554
if ($ minify ['quotes ' ]) {
@@ -568,24 +568,24 @@ public function minify(array $minify = []) : void {
568
568
}
569
569
570
570
// sort classes by occurence, then by string
571
- if (is_array ($ minify ['attributes ' ])) {
571
+ if (\ is_array ($ minify ['attributes ' ])) {
572
572
573
573
// sort attribute values by most frequent
574
574
if ($ minify ['attributes ' ]['sort ' ] && !empty ($ this ->cache ['attr ' ])) {
575
- arsort ($ this ->cache ['attr ' ]);
576
- arsort ($ this ->cache ['attrvalues ' ]);
575
+ \ arsort ($ this ->cache ['attr ' ]);
576
+ \ arsort ($ this ->cache ['attrvalues ' ]);
577
577
$ attr = [];
578
578
foreach ($ this ->cache ['attrvalues ' ] AS $ item => $ occurences ) {
579
579
if ($ occurences > 5 ) {
580
- $ item = mb_strstr ($ item , '= ' , true );
581
- if (!in_array ($ item , $ attr )) {
580
+ $ item = \ mb_strstr ($ item , '= ' , true );
581
+ if (!\ in_array ($ item , $ attr )) {
582
582
$ attr [] = $ item ;
583
583
}
584
584
} else {
585
585
break ;
586
586
}
587
587
}
588
- $ minify ['attributes ' ]['sort ' ] = array_unique (array_merge ($ attr , array_keys ($ this ->cache ['attr ' ])));
588
+ $ minify ['attributes ' ]['sort ' ] = \ array_unique (\ array_merge ($ attr , \ array_keys ($ this ->cache ['attr ' ])));
589
589
}
590
590
}
591
591
@@ -602,7 +602,7 @@ public function minify(array $minify = []) : void {
602
602
* @return string The compiled HTML
603
603
*/
604
604
public function html (array $ options = []) : string {
605
- $ options = $ options ? array_merge ($ this ->config ['output ' ], $ options ) : $ this ->config ['output ' ];
605
+ $ options = $ options ? \ array_merge ($ this ->config ['output ' ], $ options ) : $ this ->config ['output ' ];
606
606
607
607
// presets
608
608
if (!empty ($ options ['xml ' ])) {
@@ -639,16 +639,16 @@ public function save(string $file = null, array $options = []) {
639
639
}
640
640
641
641
// convert to target charset
642
- $ html = mb_convert_encoding ($ html , $ options ['charset ' ]);
642
+ $ html = \ mb_convert_encoding ($ html , $ options ['charset ' ]);
643
643
}
644
644
645
645
// send back as string
646
646
if (!$ file ) {
647
647
return $ html ;
648
648
649
649
// save file
650
- } elseif (file_put_contents ($ file , $ html ) === false ) {
651
- trigger_error ('File could not be written ' , E_USER_WARNING );
650
+ } elseif (\ file_put_contents ($ file , $ html ) === false ) {
651
+ \ trigger_error ('File could not be written ' , E_USER_WARNING );
652
652
} else {
653
653
return true ;
654
654
}
@@ -667,21 +667,21 @@ protected function htmlentities(string $html, string $charset) : string {
667
667
// generate single-byte characters
668
668
$ str = '' ;
669
669
for ($ i = 1 ; $ i < 256 ; $ i ++) {
670
- $ str .= chr ($ i );
670
+ $ str .= \ chr ($ i );
671
671
}
672
- $ str = mb_convert_encoding ($ str , mb_internal_encoding (), $ charset );
672
+ $ str = \ mb_convert_encoding ($ str , \ mb_internal_encoding (), $ charset );
673
673
674
674
// build html entities conversion map
675
675
$ replace = [];
676
- foreach (preg_split ('//u ' , $ str , -1 , PREG_SPLIT_NO_EMPTY ) AS $ chr ) {
677
- $ ent = mb_convert_encoding ($ chr , 'HTML-ENTITIES ' );
676
+ foreach (\ preg_split ('//u ' , $ str , -1 , PREG_SPLIT_NO_EMPTY ) AS $ chr ) {
677
+ $ ent = \ mb_convert_encoding ($ chr , 'HTML-ENTITIES ' );
678
678
if ($ ent != $ chr ) {
679
679
$ replace [$ chr ] = $ ent ;
680
680
}
681
681
}
682
682
683
683
// convert entities
684
- $ html = mb_convert_encoding ($ html , 'HTML-ENTITIES ' );
685
- return str_replace (array_values ($ replace ), array_keys ($ replace ), $ html );
684
+ $ html = \ mb_convert_encoding ($ html , 'HTML-ENTITIES ' );
685
+ return \ str_replace (\ array_values ($ replace ), \ array_keys ($ replace ), $ html );
686
686
}
687
687
}
0 commit comments