@@ -61,9 +61,7 @@ class Crawler implements \Countable, \IteratorAggregate
61
61
private $ html5Parser ;
62
62
63
63
/**
64
- * @param mixed $node A Node to use as the base for the crawling
65
- * @param string $uri The current URI
66
- * @param string $baseHref The base href value
64
+ * @param mixed $node A Node to use as the base for the crawling
67
65
*/
68
66
public function __construct ($ node = null , string $ uri = null , string $ baseHref = null )
69
67
{
@@ -134,11 +132,8 @@ public function add($node)
134
132
* If the charset is not set via the content type, it is assumed to be UTF-8,
135
133
* or ISO-8859-1 as a fallback, which is the default charset defined by the
136
134
* HTTP 1.1 specification.
137
- *
138
- * @param string $content A string to parse as HTML/XML
139
- * @param string|null $type The content type of the string
140
135
*/
141
- public function addContent ($ content , $ type = null )
136
+ public function addContent (string $ content , string $ type = null )
142
137
{
143
138
if (empty ($ type )) {
144
139
$ type = 0 === strpos ($ content , '<?xml ' ) ? 'application/xml ' : 'text/html ' ;
@@ -184,11 +179,8 @@ public function addContent($content, $type = null)
184
179
* internal errors via libxml_use_internal_errors(true)
185
180
* and then, get the errors via libxml_get_errors(). Be
186
181
* sure to clear errors with libxml_clear_errors() afterward.
187
- *
188
- * @param string $content The HTML content
189
- * @param string $charset The charset
190
182
*/
191
- public function addHtmlContent ($ content , $ charset = 'UTF-8 ' )
183
+ public function addHtmlContent (string $ content , string $ charset = 'UTF-8 ' )
192
184
{
193
185
// Use HTML5 parser if the content is HTML5 and the library is available
194
186
$ dom = null !== $ this ->html5Parser && strspn ($ content , " \t\r\n" ) === stripos ($ content , '<!doctype html> ' ) ? $ this ->parseHtml5 ($ content , $ charset ) : $ this ->parseXhtml ($ content , $ charset );
@@ -219,13 +211,11 @@ public function addHtmlContent($content, $charset = 'UTF-8')
219
211
* and then, get the errors via libxml_get_errors(). Be
220
212
* sure to clear errors with libxml_clear_errors() afterward.
221
213
*
222
- * @param string $content The XML content
223
- * @param string $charset The charset
224
- * @param int $options Bitwise OR of the libxml option constants
225
- * LIBXML_PARSEHUGE is dangerous, see
226
- * http://symfony.com/blog/security-release-symfony-2-0-17-released
214
+ * @param int $options Bitwise OR of the libxml option constants
215
+ * LIBXML_PARSEHUGE is dangerous, see
216
+ * http://symfony.com/blog/security-release-symfony-2-0-17-released
227
217
*/
228
- public function addXmlContent ($ content , $ charset = 'UTF-8 ' , $ options = LIBXML_NONET )
218
+ public function addXmlContent (string $ content , string $ charset = 'UTF-8 ' , int $ options = LIBXML_NONET )
229
219
{
230
220
// remove the default namespace if it's the only namespace to make XPath expressions simpler
231
221
if (!preg_match ('/xmlns:/ ' , $ content )) {
@@ -318,11 +308,9 @@ public function addNode(\DOMNode $node)
318
308
/**
319
309
* Returns a node given its position in the node list.
320
310
*
321
- * @param int $position The position
322
- *
323
311
* @return self
324
312
*/
325
- public function eq ($ position )
313
+ public function eq (int $ position )
326
314
{
327
315
if (isset ($ this ->nodes [$ position ])) {
328
316
return $ this ->createSubCrawler ($ this ->nodes [$ position ]);
@@ -360,12 +348,9 @@ public function each(\Closure $closure)
360
348
/**
361
349
* Slices the list of nodes by $offset and $length.
362
350
*
363
- * @param int $offset
364
- * @param int $length
365
- *
366
351
* @return self
367
352
*/
368
- public function slice ($ offset = 0 , $ length = null )
353
+ public function slice (int $ offset = 0 , int $ length = null )
369
354
{
370
355
return $ this ->createSubCrawler (\array_slice ($ this ->nodes , $ offset , $ length ));
371
356
}
@@ -487,8 +472,6 @@ public function parents()
487
472
/**
488
473
* Returns the children nodes of the current selection.
489
474
*
490
- * @param string|null $selector An optional CSS selector to filter children
491
- *
492
475
* @return self
493
476
*
494
477
* @throws \InvalidArgumentException When current node is empty
@@ -515,13 +498,11 @@ public function children(string $selector = null)
515
498
/**
516
499
* Returns the attribute value of the first node of the list.
517
500
*
518
- * @param string $attribute The attribute name
519
- *
520
501
* @return string|null The attribute value or null if the attribute does not exist
521
502
*
522
503
* @throws \InvalidArgumentException When current node is empty
523
504
*/
524
- public function attr ($ attribute )
505
+ public function attr (string $ attribute )
525
506
{
526
507
if (!$ this ->nodes ) {
527
508
throw new \InvalidArgumentException ('The current node list is empty. ' );
@@ -610,11 +591,9 @@ public function html($default = null)
610
591
* Since an XPath expression might evaluate to either a simple type or a \DOMNodeList,
611
592
* this method will return either an array of simple types or a new Crawler instance.
612
593
*
613
- * @param string $xpath An XPath expression
614
- *
615
594
* @return array|Crawler An array of evaluation results or a new Crawler instance
616
595
*/
617
- public function evaluate ($ xpath )
596
+ public function evaluate (string $ xpath )
618
597
{
619
598
if (null === $ this ->document ) {
620
599
throw new \LogicException ('Cannot evaluate the expression on an uninitialized crawler. ' );
@@ -643,13 +622,10 @@ public function evaluate($xpath)
643
622
*
644
623
* $crawler->filter('h1 a')->extract(['_text', 'href']);
645
624
*
646
- * @param array $attributes An array of attributes
647
- *
648
625
* @return array An array of extracted values
649
626
*/
650
- public function extract ($ attributes )
627
+ public function extract (array $ attributes )
651
628
{
652
- $ attributes = (array ) $ attributes ;
653
629
$ count = \count ($ attributes );
654
630
655
631
$ data = [];
@@ -679,11 +655,9 @@ public function extract($attributes)
679
655
* This means that a child selector "div" or "./div" will match only
680
656
* the div elements of the current crawler, not their children.
681
657
*
682
- * @param string $xpath An XPath expression
683
- *
684
658
* @return self
685
659
*/
686
- public function filterXPath ($ xpath )
660
+ public function filterXPath (string $ xpath )
687
661
{
688
662
$ xpath = $ this ->relativize ($ xpath );
689
663
@@ -700,13 +674,11 @@ public function filterXPath($xpath)
700
674
*
701
675
* This method only works if you have installed the CssSelector Symfony Component.
702
676
*
703
- * @param string $selector A CSS selector
704
- *
705
677
* @return self
706
678
*
707
679
* @throws \RuntimeException if the CssSelector Component is not available
708
680
*/
709
- public function filter ($ selector )
681
+ public function filter (string $ selector )
710
682
{
711
683
$ converter = $ this ->createCssSelectorConverter ();
712
684
@@ -717,11 +689,9 @@ public function filter($selector)
717
689
/**
718
690
* Selects links by name or alt value for clickable images.
719
691
*
720
- * @param string $value The link text
721
- *
722
692
* @return self
723
693
*/
724
- public function selectLink ($ value )
694
+ public function selectLink (string $ value )
725
695
{
726
696
return $ this ->filterRelativeXPath (
727
697
sprintf ('descendant-or-self::a[contains(concat( \' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat( \' \', normalize-space(string(@alt)), \' \'), %1$s)]] ' , static ::xpathLiteral (' ' .$ value .' ' ))
@@ -731,11 +701,9 @@ public function selectLink($value)
731
701
/**
732
702
* Selects images by alt value.
733
703
*
734
- * @param string $value The image alt
735
- *
736
704
* @return self A new instance of Crawler with the filtered list of nodes
737
705
*/
738
- public function selectImage ($ value )
706
+ public function selectImage (string $ value )
739
707
{
740
708
$ xpath = sprintf ('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)] ' , static ::xpathLiteral ($ value ));
741
709
@@ -745,11 +713,9 @@ public function selectImage($value)
745
713
/**
746
714
* Selects a button by name or alt value for images.
747
715
*
748
- * @param string $value The button text
749
- *
750
716
* @return self
751
717
*/
752
- public function selectButton ($ value )
718
+ public function selectButton (string $ value )
753
719
{
754
720
return $ this ->filterRelativeXPath (
755
721
sprintf ('descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat( \' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat( \' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat( \' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s] ' , 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz") ' , static ::xpathLiteral (' ' .$ value .' ' ), static ::xpathLiteral ($ value ))
@@ -759,13 +725,11 @@ public function selectButton($value)
759
725
/**
760
726
* Returns a Link object for the first node in the list.
761
727
*
762
- * @param string $method The method for the link (get by default)
763
- *
764
728
* @return Link A Link instance
765
729
*
766
730
* @throws \InvalidArgumentException If the current node list is empty or the selected node is not instance of DOMElement
767
731
*/
768
- public function link ($ method = 'get ' )
732
+ public function link (string $ method = 'get ' )
769
733
{
770
734
if (!$ this ->nodes ) {
771
735
throw new \InvalidArgumentException ('The current node list is empty. ' );
@@ -845,9 +809,6 @@ public function images()
845
809
/**
846
810
* Returns a Form object for the first node in the list.
847
811
*
848
- * @param array $values An array of values for the form fields
849
- * @param string $method The method for the form
850
- *
851
812
* @return Form A Form instance
852
813
*
853
814
* @throws \InvalidArgumentException If the current node list is empty or the selected node is not instance of DOMElement
@@ -875,19 +836,13 @@ public function form(array $values = null, $method = null)
875
836
876
837
/**
877
838
* Overloads a default namespace prefix to be used with XPath and CSS expressions.
878
- *
879
- * @param string $prefix
880
839
*/
881
- public function setDefaultNamespacePrefix ($ prefix )
840
+ public function setDefaultNamespacePrefix (string $ prefix )
882
841
{
883
842
$ this ->defaultNamespacePrefix = $ prefix ;
884
843
}
885
844
886
- /**
887
- * @param string $prefix
888
- * @param string $namespace
889
- */
890
- public function registerNamespace ($ prefix , $ namespace )
845
+ public function registerNamespace (string $ prefix , string $ namespace )
891
846
{
892
847
$ this ->namespaces [$ prefix ] = $ namespace ;
893
848
}
@@ -909,11 +864,9 @@ public function registerNamespace($prefix, $namespace)
909
864
* //prints concat('a', "'", 'b"c')
910
865
*
911
866
*
912
- * @param string $s String to be escaped
913
- *
914
867
* @return string Converted string
915
868
*/
916
- public static function xpathLiteral ($ s )
869
+ public static function xpathLiteral (string $ s )
917
870
{
918
871
if (false === strpos ($ s , "' " )) {
919
872
return sprintf ("'%s' " , $ s );
@@ -944,11 +897,9 @@ public static function xpathLiteral($s)
944
897
*
945
898
* The XPath expression should already be processed to apply it in the context of each node.
946
899
*
947
- * @param string $xpath
948
- *
949
900
* @return self
950
901
*/
951
- private function filterRelativeXPath ($ xpath )
902
+ private function filterRelativeXPath (string $ xpath )
952
903
{
953
904
$ prefixes = $ this ->findNamespacePrefixes ($ xpath );
954
905
@@ -1053,11 +1004,9 @@ private function relativize(string $xpath): string
1053
1004
}
1054
1005
1055
1006
/**
1056
- * @param int $position
1057
- *
1058
1007
* @return \DOMElement|null
1059
1008
*/
1060
- public function getNode ($ position )
1009
+ public function getNode (int $ position )
1061
1010
{
1062
1011
if (isset ($ this ->nodes [$ position ])) {
1063
1012
return $ this ->nodes [$ position ];
@@ -1081,12 +1030,9 @@ public function getIterator()
1081
1030
}
1082
1031
1083
1032
/**
1084
- * @param \DOMElement $node
1085
- * @param string $siblingDir
1086
- *
1087
1033
* @return array
1088
1034
*/
1089
- protected function sibling ($ node , $ siblingDir = 'nextSibling ' )
1035
+ protected function sibling ($ node , string $ siblingDir = 'nextSibling ' )
1090
1036
{
1091
1037
$ nodes = [];
1092
1038
0 commit comments