Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e809256

Browse filesBrowse files
committed
[DomCrawler] [5.0] add type-hint whenever possible
1 parent 8fb4741 commit e809256
Copy full SHA for e809256

File tree

9 files changed

+46
-125
lines changed
Filter options

9 files changed

+46
-125
lines changed

‎src/Symfony/Component/DomCrawler/AbstractUriElement.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/AbstractUriElement.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ abstract protected function getRawUri();
136136
*
137137
* @return string
138138
*/
139-
protected function canonicalizePath($path)
139+
protected function canonicalizePath(string $path)
140140
{
141141
if ('' === $path || '/' === $path) {
142142
return $path;

‎src/Symfony/Component/DomCrawler/Crawler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Crawler.php
+20-73Lines changed: 20 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class Crawler implements \Countable, \IteratorAggregate
6262

6363
/**
6464
* @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
6765
*/
6866
public function __construct($node = null, string $uri = null, string $baseHref = null)
6967
{
@@ -135,10 +133,8 @@ public function add($node)
135133
* or ISO-8859-1 as a fallback, which is the default charset defined by the
136134
* HTTP 1.1 specification.
137135
*
138-
* @param string $content A string to parse as HTML/XML
139-
* @param string|null $type The content type of the string
140136
*/
141-
public function addContent($content, $type = null)
137+
public function addContent(string $content, string $type = null)
142138
{
143139
if (empty($type)) {
144140
$type = 0 === strpos($content, '<?xml') ? 'application/xml' : 'text/html';
@@ -184,11 +180,8 @@ public function addContent($content, $type = null)
184180
* internal errors via libxml_use_internal_errors(true)
185181
* and then, get the errors via libxml_get_errors(). Be
186182
* sure to clear errors with libxml_clear_errors() afterward.
187-
*
188-
* @param string $content The HTML content
189-
* @param string $charset The charset
190183
*/
191-
public function addHtmlContent($content, $charset = 'UTF-8')
184+
public function addHtmlContent(string $content, string $charset = 'UTF-8')
192185
{
193186
// Use HTML5 parser if the content is HTML5 and the library is available
194187
$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')
219212
* and then, get the errors via libxml_get_errors(). Be
220213
* sure to clear errors with libxml_clear_errors() afterward.
221214
*
222-
* @param string $content The XML content
223-
* @param string $charset The charset
224215
* @param int $options Bitwise OR of the libxml option constants
225216
* LIBXML_PARSEHUGE is dangerous, see
226217
* http://symfony.com/blog/security-release-symfony-2-0-17-released
227218
*/
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)
229220
{
230221
// remove the default namespace if it's the only namespace to make XPath expressions simpler
231222
if (!preg_match('/xmlns:/', $content)) {
@@ -318,11 +309,9 @@ public function addNode(\DOMNode $node)
318309
/**
319310
* Returns a node given its position in the node list.
320311
*
321-
* @param int $position The position
322-
*
323312
* @return self
324313
*/
325-
public function eq($position)
314+
public function eq(int $position)
326315
{
327316
if (isset($this->nodes[$position])) {
328317
return $this->createSubCrawler($this->nodes[$position]);
@@ -360,12 +349,9 @@ public function each(\Closure $closure)
360349
/**
361350
* Slices the list of nodes by $offset and $length.
362351
*
363-
* @param int $offset
364-
* @param int $length
365-
*
366352
* @return self
367353
*/
368-
public function slice($offset = 0, $length = null)
354+
public function slice(int $offset = 0, int $length = null)
369355
{
370356
return $this->createSubCrawler(\array_slice($this->nodes, $offset, $length));
371357
}
@@ -487,8 +473,6 @@ public function parents()
487473
/**
488474
* Returns the children nodes of the current selection.
489475
*
490-
* @param string|null $selector An optional CSS selector to filter children
491-
*
492476
* @return self
493477
*
494478
* @throws \InvalidArgumentException When current node is empty
@@ -515,13 +499,11 @@ public function children(string $selector = null)
515499
/**
516500
* Returns the attribute value of the first node of the list.
517501
*
518-
* @param string $attribute The attribute name
519-
*
520502
* @return string|null The attribute value or null if the attribute does not exist
521503
*
522504
* @throws \InvalidArgumentException When current node is empty
523505
*/
524-
public function attr($attribute)
506+
public function attr(string $attribute)
525507
{
526508
if (!$this->nodes) {
527509
throw new \InvalidArgumentException('The current node list is empty.');
@@ -610,11 +592,9 @@ public function html($default = null)
610592
* Since an XPath expression might evaluate to either a simple type or a \DOMNodeList,
611593
* this method will return either an array of simple types or a new Crawler instance.
612594
*
613-
* @param string $xpath An XPath expression
614-
*
615595
* @return array|Crawler An array of evaluation results or a new Crawler instance
616596
*/
617-
public function evaluate($xpath)
597+
public function evaluate(string $xpath)
618598
{
619599
if (null === $this->document) {
620600
throw new \LogicException('Cannot evaluate the expression on an uninitialized crawler.');
@@ -643,13 +623,10 @@ public function evaluate($xpath)
643623
*
644624
* $crawler->filter('h1 a')->extract(['_text', 'href']);
645625
*
646-
* @param array $attributes An array of attributes
647-
*
648626
* @return array An array of extracted values
649627
*/
650-
public function extract($attributes)
628+
public function extract(array $attributes)
651629
{
652-
$attributes = (array) $attributes;
653630
$count = \count($attributes);
654631

655632
$data = [];
@@ -679,11 +656,9 @@ public function extract($attributes)
679656
* This means that a child selector "div" or "./div" will match only
680657
* the div elements of the current crawler, not their children.
681658
*
682-
* @param string $xpath An XPath expression
683-
*
684659
* @return self
685660
*/
686-
public function filterXPath($xpath)
661+
public function filterXPath(string $xpath)
687662
{
688663
$xpath = $this->relativize($xpath);
689664

@@ -700,13 +675,11 @@ public function filterXPath($xpath)
700675
*
701676
* This method only works if you have installed the CssSelector Symfony Component.
702677
*
703-
* @param string $selector A CSS selector
704-
*
705678
* @return self
706679
*
707680
* @throws \RuntimeException if the CssSelector Component is not available
708681
*/
709-
public function filter($selector)
682+
public function filter(string $selector)
710683
{
711684
$converter = $this->createCssSelectorConverter();
712685

@@ -717,11 +690,9 @@ public function filter($selector)
717690
/**
718691
* Selects links by name or alt value for clickable images.
719692
*
720-
* @param string $value The link text
721-
*
722693
* @return self
723694
*/
724-
public function selectLink($value)
695+
public function selectLink(string $value)
725696
{
726697
return $this->filterRelativeXPath(
727698
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)
731702
/**
732703
* Selects images by alt value.
733704
*
734-
* @param string $value The image alt
735-
*
736705
* @return self A new instance of Crawler with the filtered list of nodes
737706
*/
738-
public function selectImage($value)
707+
public function selectImage(string $value)
739708
{
740709
$xpath = sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', static::xpathLiteral($value));
741710

@@ -745,11 +714,9 @@ public function selectImage($value)
745714
/**
746715
* Selects a button by name or alt value for images.
747716
*
748-
* @param string $value The button text
749-
*
750717
* @return self
751718
*/
752-
public function selectButton($value)
719+
public function selectButton(string $value)
753720
{
754721
return $this->filterRelativeXPath(
755722
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)
759726
/**
760727
* Returns a Link object for the first node in the list.
761728
*
762-
* @param string $method The method for the link (get by default)
763-
*
764729
* @return Link A Link instance
765730
*
766731
* @throws \InvalidArgumentException If the current node list is empty or the selected node is not instance of DOMElement
767732
*/
768-
public function link($method = 'get')
733+
public function link(string $method = 'get')
769734
{
770735
if (!$this->nodes) {
771736
throw new \InvalidArgumentException('The current node list is empty.');
@@ -845,9 +810,6 @@ public function images()
845810
/**
846811
* Returns a Form object for the first node in the list.
847812
*
848-
* @param array $values An array of values for the form fields
849-
* @param string $method The method for the form
850-
*
851813
* @return Form A Form instance
852814
*
853815
* @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)
875837

876838
/**
877839
* Overloads a default namespace prefix to be used with XPath and CSS expressions.
878-
*
879-
* @param string $prefix
880840
*/
881-
public function setDefaultNamespacePrefix($prefix)
841+
public function setDefaultNamespacePrefix(string $prefix)
882842
{
883843
$this->defaultNamespacePrefix = $prefix;
884844
}
885845

886-
/**
887-
* @param string $prefix
888-
* @param string $namespace
889-
*/
890-
public function registerNamespace($prefix, $namespace)
846+
public function registerNamespace(string $prefix, string $namespace)
891847
{
892848
$this->namespaces[$prefix] = $namespace;
893849
}
@@ -909,11 +865,9 @@ public function registerNamespace($prefix, $namespace)
909865
* //prints concat('a', "'", 'b"c')
910866
*
911867
*
912-
* @param string $s String to be escaped
913-
*
914868
* @return string Converted string
915869
*/
916-
public static function xpathLiteral($s)
870+
public static function xpathLiteral(string $s)
917871
{
918872
if (false === strpos($s, "'")) {
919873
return sprintf("'%s'", $s);
@@ -944,11 +898,9 @@ public static function xpathLiteral($s)
944898
*
945899
* The XPath expression should already be processed to apply it in the context of each node.
946900
*
947-
* @param string $xpath
948-
*
949901
* @return self
950902
*/
951-
private function filterRelativeXPath($xpath)
903+
private function filterRelativeXPath(string $xpath)
952904
{
953905
$prefixes = $this->findNamespacePrefixes($xpath);
954906

@@ -1053,11 +1005,9 @@ private function relativize(string $xpath): string
10531005
}
10541006

10551007
/**
1056-
* @param int $position
1057-
*
10581008
* @return \DOMElement|null
10591009
*/
1060-
public function getNode($position)
1010+
public function getNode(int $position)
10611011
{
10621012
if (isset($this->nodes[$position])) {
10631013
return $this->nodes[$position];
@@ -1081,12 +1031,9 @@ public function getIterator()
10811031
}
10821032

10831033
/**
1084-
* @param \DOMElement $node
1085-
* @param string $siblingDir
1086-
*
10871034
* @return array
10881035
*/
1089-
protected function sibling($node, $siblingDir = 'nextSibling')
1036+
protected function sibling($node, string $siblingDir = 'nextSibling')
10901037
{
10911038
$nodes = [];
10921039

‎src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,9 @@ private function buildOptionValue(\DOMElement $node): array
270270
/**
271271
* Checks whether given value is in the existing options.
272272
*
273-
* @param string $optionValue
274-
* @param array $options
275-
*
276273
* @return bool
277274
*/
278-
public function containsOption($optionValue, $options)
275+
public function containsOption(string $optionValue, array $options)
279276
{
280277
if ($this->validationDisabled) {
281278
return true;

‎src/Symfony/Component/DomCrawler/Field/FileFormField.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Field/FileFormField.php
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FileFormField extends FormField
2525
*
2626
* @throws \InvalidArgumentException When error code doesn't exist
2727
*/
28-
public function setErrorCode($error)
28+
public function setErrorCode(int $error)
2929
{
3030
$codes = [UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION];
3131
if (!\in_array($error, $codes)) {
@@ -37,20 +37,16 @@ public function setErrorCode($error)
3737

3838
/**
3939
* Sets the value of the field.
40-
*
41-
* @param string $value The value of the field
4240
*/
43-
public function upload($value)
41+
public function upload(?string $value)
4442
{
4543
$this->setValue($value);
4644
}
4745

4846
/**
4947
* Sets the value of the field.
50-
*
51-
* @param string $value The value of the field
5248
*/
53-
public function setValue($value)
49+
public function setValue(?string $value)
5450
{
5551
if (null !== $value && is_readable($value)) {
5652
$error = UPLOAD_ERR_OK;
@@ -80,10 +76,8 @@ public function setValue($value)
8076

8177
/**
8278
* Sets path to the file as string for simulating HTTP request.
83-
*
84-
* @param string $path The path to the file
8579
*/
86-
public function setFilePath($path)
80+
public function setFilePath(string $path)
8781
{
8882
parent::setValue($path);
8983
}

‎src/Symfony/Component/DomCrawler/Field/FormField.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Field/FormField.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ public function getValue()
102102
*
103103
* @param string $value The value of the field
104104
*/
105-
public function setValue($value)
105+
public function setValue(?string $value)
106106
{
107-
$this->value = (string) $value;
107+
$this->value = $value;
108108
}
109109

110110
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.