@@ -30,7 +30,7 @@ class Crawler implements \Countable, \IteratorAggregate
30
30
/**
31
31
* @var array A map of manually registered namespaces
32
32
*/
33
- private $ namespaces = array () ;
33
+ private $ namespaces = [] ;
34
34
35
35
/**
36
36
* @var string The base href value
@@ -45,7 +45,7 @@ class Crawler implements \Countable, \IteratorAggregate
45
45
/**
46
46
* @var \DOMElement[]
47
47
*/
48
- private $ nodes = array () ;
48
+ private $ nodes = [] ;
49
49
50
50
/**
51
51
* Whether the Crawler contains HTML or XML content (used when converting CSS to XPath).
@@ -92,7 +92,7 @@ public function getBaseHref()
92
92
*/
93
93
public function clear ()
94
94
{
95
- $ this ->nodes = array () ;
95
+ $ this ->nodes = [] ;
96
96
$ this ->document = null ;
97
97
}
98
98
@@ -208,7 +208,7 @@ public function addHtmlContent($content, $charset = 'UTF-8')
208
208
209
209
$ this ->addDocument ($ dom );
210
210
211
- $ base = $ this ->filterRelativeXPath ('descendant-or-self::base ' )->extract (array ( 'href ' ) );
211
+ $ base = $ this ->filterRelativeXPath ('descendant-or-self::base ' )->extract ([ 'href ' ] );
212
212
213
213
$ baseHref = current ($ base );
214
214
if (\count ($ base ) && !empty ($ baseHref )) {
@@ -363,7 +363,7 @@ public function eq($position)
363
363
*/
364
364
public function each (\Closure $ closure )
365
365
{
366
- $ data = array () ;
366
+ $ data = [] ;
367
367
foreach ($ this ->nodes as $ i => $ node ) {
368
368
$ data [] = $ closure ($ this ->createSubCrawler ($ node ), $ i );
369
369
}
@@ -395,7 +395,7 @@ public function slice($offset = 0, $length = null)
395
395
*/
396
396
public function reduce (\Closure $ closure )
397
397
{
398
- $ nodes = array () ;
398
+ $ nodes = [] ;
399
399
foreach ($ this ->nodes as $ i => $ node ) {
400
400
if (false !== $ closure ($ this ->createSubCrawler ($ node ), $ i )) {
401
401
$ nodes [] = $ node ;
@@ -487,7 +487,7 @@ public function parents()
487
487
}
488
488
489
489
$ node = $ this ->getNode (0 );
490
- $ nodes = array () ;
490
+ $ nodes = [] ;
491
491
492
492
while ($ node = $ node ->parentNode ) {
493
493
if (XML_ELEMENT_NODE === $ node ->nodeType ) {
@@ -513,7 +513,7 @@ public function children()
513
513
514
514
$ node = $ this ->getNode (0 )->firstChild ;
515
515
516
- return $ this ->createSubCrawler ($ node ? $ this ->sibling ($ node ) : array () );
516
+ return $ this ->createSubCrawler ($ node ? $ this ->sibling ($ node ) : [] );
517
517
}
518
518
519
519
/**
@@ -605,7 +605,7 @@ public function evaluate($xpath)
605
605
throw new \LogicException ('Cannot evaluate the expression on an uninitialized crawler. ' );
606
606
}
607
607
608
- $ data = array () ;
608
+ $ data = [] ;
609
609
$ domxpath = $ this ->createDOMXPath ($ this ->document , $ this ->findNamespacePrefixes ($ xpath ));
610
610
611
611
foreach ($ this ->nodes as $ node ) {
@@ -637,9 +637,9 @@ public function extract($attributes)
637
637
$ attributes = (array ) $ attributes ;
638
638
$ count = \count ($ attributes );
639
639
640
- $ data = array () ;
640
+ $ data = [] ;
641
641
foreach ($ this ->nodes as $ node ) {
642
- $ elements = array () ;
642
+ $ elements = [] ;
643
643
foreach ($ attributes as $ attribute ) {
644
644
if ('_text ' === $ attribute ) {
645
645
$ elements [] = $ node ->nodeValue ;
@@ -776,7 +776,7 @@ public function link($method = 'get')
776
776
*/
777
777
public function links ()
778
778
{
779
- $ links = array () ;
779
+ $ links = [] ;
780
780
foreach ($ this ->nodes as $ node ) {
781
781
if (!$ node instanceof \DOMElement) {
782
782
throw new \InvalidArgumentException (sprintf ('The current node list should contain only DOMElement instances, "%s" found. ' , \get_class ($ node )));
@@ -817,7 +817,7 @@ public function image()
817
817
*/
818
818
public function images ()
819
819
{
820
- $ images = array () ;
820
+ $ images = [] ;
821
821
foreach ($ this as $ node ) {
822
822
if (!$ node instanceof \DOMElement) {
823
823
throw new \InvalidArgumentException (sprintf ('The current node list should contain only DOMElement instances, "%s" found. ' , \get_class ($ node )));
@@ -911,7 +911,7 @@ public static function xpathLiteral($s)
911
911
}
912
912
913
913
$ string = $ s ;
914
- $ parts = array () ;
914
+ $ parts = [] ;
915
915
while (true ) {
916
916
if (false !== $ pos = strpos ($ string , "' " )) {
917
917
$ parts [] = sprintf ("'%s' " , substr ($ string , 0 , $ pos ));
@@ -957,7 +957,7 @@ private function filterRelativeXPath($xpath)
957
957
*/
958
958
private function relativize (string $ xpath ): string
959
959
{
960
- $ expressions = array () ;
960
+ $ expressions = [] ;
961
961
962
962
// An expression which will never match to replace expressions which cannot match in the crawler
963
963
// We cannot simply drop
@@ -1075,7 +1075,7 @@ public function getIterator()
1075
1075
*/
1076
1076
protected function sibling ($ node , $ siblingDir = 'nextSibling ' )
1077
1077
{
1078
- $ nodes = array () ;
1078
+ $ nodes = [] ;
1079
1079
1080
1080
$ currentNode = $ this ->getNode (0 );
1081
1081
do {
@@ -1090,7 +1090,7 @@ protected function sibling($node, $siblingDir = 'nextSibling')
1090
1090
/**
1091
1091
* @throws \InvalidArgumentException
1092
1092
*/
1093
- private function createDOMXPath (\DOMDocument $ document , array $ prefixes = array () ): \DOMXPath
1093
+ private function createDOMXPath (\DOMDocument $ document , array $ prefixes = [] ): \DOMXPath
1094
1094
{
1095
1095
$ domxpath = new \DOMXPath ($ document );
1096
1096
@@ -1129,7 +1129,7 @@ private function findNamespacePrefixes(string $xpath): array
1129
1129
return array_unique ($ matches ['prefix ' ]);
1130
1130
}
1131
1131
1132
- return array () ;
1132
+ return [] ;
1133
1133
}
1134
1134
1135
1135
/**
0 commit comments