@@ -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 ) {
@@ -528,7 +528,7 @@ public function children(/* string $selector = null */)
528
528
529
529
$ node = $ this ->getNode (0 )->firstChild ;
530
530
531
- return $ this ->createSubCrawler ($ node ? $ this ->sibling ($ node ) : array () );
531
+ return $ this ->createSubCrawler ($ node ? $ this ->sibling ($ node ) : [] );
532
532
}
533
533
534
534
/**
@@ -620,7 +620,7 @@ public function evaluate($xpath)
620
620
throw new \LogicException ('Cannot evaluate the expression on an uninitialized crawler. ' );
621
621
}
622
622
623
- $ data = array () ;
623
+ $ data = [] ;
624
624
$ domxpath = $ this ->createDOMXPath ($ this ->document , $ this ->findNamespacePrefixes ($ xpath ));
625
625
626
626
foreach ($ this ->nodes as $ node ) {
@@ -641,7 +641,7 @@ public function evaluate($xpath)
641
641
*
642
642
* Example:
643
643
*
644
- * $crawler->filter('h1 a')->extract(array( '_text', 'href') );
644
+ * $crawler->filter('h1 a')->extract([ '_text', 'href'] );
645
645
*
646
646
* @param array $attributes An array of attributes
647
647
*
@@ -652,9 +652,9 @@ public function extract($attributes)
652
652
$ attributes = (array ) $ attributes ;
653
653
$ count = \count ($ attributes );
654
654
655
- $ data = array () ;
655
+ $ data = [] ;
656
656
foreach ($ this ->nodes as $ node ) {
657
- $ elements = array () ;
657
+ $ elements = [] ;
658
658
foreach ($ attributes as $ attribute ) {
659
659
if ('_text ' === $ attribute ) {
660
660
$ elements [] = $ node ->nodeValue ;
@@ -787,7 +787,7 @@ public function link($method = 'get')
787
787
*/
788
788
public function links ()
789
789
{
790
- $ links = array () ;
790
+ $ links = [] ;
791
791
foreach ($ this ->nodes as $ node ) {
792
792
if (!$ node instanceof \DOMElement) {
793
793
throw new \InvalidArgumentException (sprintf ('The current node list should contain only DOMElement instances, "%s" found. ' , \get_class ($ node )));
@@ -828,7 +828,7 @@ public function image()
828
828
*/
829
829
public function images ()
830
830
{
831
- $ images = array () ;
831
+ $ images = [] ;
832
832
foreach ($ this as $ node ) {
833
833
if (!$ node instanceof \DOMElement) {
834
834
throw new \InvalidArgumentException (sprintf ('The current node list should contain only DOMElement instances, "%s" found. ' , \get_class ($ node )));
@@ -922,7 +922,7 @@ public static function xpathLiteral($s)
922
922
}
923
923
924
924
$ string = $ s ;
925
- $ parts = array () ;
925
+ $ parts = [] ;
926
926
while (true ) {
927
927
if (false !== $ pos = strpos ($ string , "' " )) {
928
928
$ parts [] = sprintf ("'%s' " , substr ($ string , 0 , $ pos ));
@@ -968,7 +968,7 @@ private function filterRelativeXPath($xpath)
968
968
*/
969
969
private function relativize (string $ xpath ): string
970
970
{
971
- $ expressions = array () ;
971
+ $ expressions = [] ;
972
972
973
973
// An expression which will never match to replace expressions which cannot match in the crawler
974
974
// We cannot simply drop
@@ -1086,7 +1086,7 @@ public function getIterator()
1086
1086
*/
1087
1087
protected function sibling ($ node , $ siblingDir = 'nextSibling ' )
1088
1088
{
1089
- $ nodes = array () ;
1089
+ $ nodes = [] ;
1090
1090
1091
1091
$ currentNode = $ this ->getNode (0 );
1092
1092
do {
@@ -1101,7 +1101,7 @@ protected function sibling($node, $siblingDir = 'nextSibling')
1101
1101
/**
1102
1102
* @throws \InvalidArgumentException
1103
1103
*/
1104
- private function createDOMXPath (\DOMDocument $ document , array $ prefixes = array () ): \DOMXPath
1104
+ private function createDOMXPath (\DOMDocument $ document , array $ prefixes = [] ): \DOMXPath
1105
1105
{
1106
1106
$ domxpath = new \DOMXPath ($ document );
1107
1107
@@ -1140,7 +1140,7 @@ private function findNamespacePrefixes(string $xpath): array
1140
1140
return array_unique ($ matches ['prefix ' ]);
1141
1141
}
1142
1142
1143
- return array () ;
1143
+ return [] ;
1144
1144
}
1145
1145
1146
1146
/**
0 commit comments