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