Skip to content

Commit c055dcc

Browse files
Add union types
1 parent ab4b299 commit c055dcc

File tree

5 files changed

+15
-34
lines changed

5 files changed

+15
-34
lines changed

Crawler.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Crawler implements \Countable, \IteratorAggregate
6868
/**
6969
* @param \DOMNodeList|\DOMNode|\DOMNode[]|string|null $node A Node to use as the base for the crawling
7070
*/
71-
public function __construct($node = null, string $uri = null, string $baseHref = null)
71+
public function __construct(\DOMNodeList|\DOMNode|array|string|null $node = null, string $uri = null, string $baseHref = null)
7272
{
7373
$this->uri = $uri;
7474
$this->baseHref = $baseHref ?: $uri;
@@ -118,7 +118,7 @@ public function clear()
118118
*
119119
* @throws \InvalidArgumentException when node is not the expected type
120120
*/
121-
public function add($node)
121+
public function add(\DOMNodeList|\DOMNode|array|string|null $node)
122122
{
123123
if ($node instanceof \DOMNodeList) {
124124
$this->addNodeList($node);
@@ -1097,11 +1097,9 @@ public function getIterator()
10971097
}
10981098

10991099
/**
1100-
* @param \DOMElement $node
1101-
*
11021100
* @return array
11031101
*/
1104-
protected function sibling($node, string $siblingDir = 'nextSibling')
1102+
protected function sibling(\DOMNode $node, string $siblingDir = 'nextSibling')
11051103
{
11061104
$nodes = [];
11071105

@@ -1212,7 +1210,7 @@ private function findNamespacePrefixes(string $xpath): array
12121210
*
12131211
* @return static
12141212
*/
1215-
private function createSubCrawler($nodes): object
1213+
private function createSubCrawler(\DOMNodeList|\DOMNode|array|string|null $nodes): object
12161214
{
12171215
$crawler = new static($nodes, $this->uri, $this->baseHref);
12181216
$crawler->isHtml = $this->isHtml;

Field/ChoiceFormField.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ public function isDisabled()
7474

7575
/**
7676
* Sets the value of the field.
77-
*
78-
* @param string|array $value The value of the field
7977
*/
80-
public function select($value)
78+
public function select(string|array|bool $value)
8179
{
8280
$this->setValue($value);
8381
}
@@ -113,11 +111,9 @@ public function untick()
113111
/**
114112
* Sets the value of the field.
115113
*
116-
* @param string|array|bool|null $value The value of the field
117-
*
118114
* @throws \InvalidArgumentException When value type provided is not correct
119115
*/
120-
public function setValue($value)
116+
public function setValue(string|array|bool|null $value)
121117
{
122118
if ('checkbox' === $this->type && false === $value) {
123119
// uncheck
@@ -290,11 +286,9 @@ public function containsOption(string $optionValue, array $options)
290286
/**
291287
* Returns list of available field options.
292288
*
293-
* @internal since Symfony 5.3
294-
*
295-
* @return array
289+
* @internal
296290
*/
297-
public function availableOptionValues()
291+
public function availableOptionValues(): array
298292
{
299293
$values = [];
300294

@@ -308,11 +302,9 @@ public function availableOptionValues()
308302
/**
309303
* Disables the internal validation of the field.
310304
*
311-
* @internal since Symfony 5.3
312-
*
313-
* @return self
305+
* @internal
314306
*/
315-
public function disableValidation()
307+
public function disableValidation(): static
316308
{
317309
$this->validationDisabled = true;
318310

Form.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function all()
315315
*
316316
* @return bool true if the field exists, false otherwise
317317
*/
318-
public function offsetExists($name)
318+
public function offsetExists(mixed $name)
319319
{
320320
return $this->has($name);
321321
}
@@ -329,7 +329,7 @@ public function offsetExists($name)
329329
*
330330
* @throws \InvalidArgumentException if the field does not exist
331331
*/
332-
public function offsetGet($name)
332+
public function offsetGet(mixed $name)
333333
{
334334
return $this->fields->get($name);
335335
}
@@ -342,7 +342,7 @@ public function offsetGet($name)
342342
*
343343
* @throws \InvalidArgumentException if the field does not exist
344344
*/
345-
public function offsetSet($name, $value)
345+
public function offsetSet(mixed $name, mixed $value)
346346
{
347347
$this->fields->set($name, $value);
348348
}
@@ -352,7 +352,7 @@ public function offsetSet($name, $value)
352352
*
353353
* @param string $name The field name
354354
*/
355-
public function offsetUnset($name)
355+
public function offsetUnset(mixed $name)
356356
{
357357
$this->fields->remove($name);
358358
}

FormFieldRegistry.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,9 @@ public function has(string $name): bool
104104
/**
105105
* Set the value of a field based on the fully qualified name and its children.
106106
*
107-
* @param mixed $value The value
108-
*
109107
* @throws \InvalidArgumentException if the field does not exist
110108
*/
111-
public function set(string $name, $value)
109+
public function set(string $name, mixed $value)
112110
{
113111
$target = &$this->get($name);
114112
if ((!\is_array($value) && $target instanceof Field\FormField) || $target instanceof Field\ChoiceFormField) {

Tests/AbstractCrawlerTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ public function testAdd()
8282
$this->assertEquals('Foo', $crawler->filterXPath('//body')->text(), '->add() adds nodes from a string');
8383
}
8484

85-
public function testAddInvalidType()
86-
{
87-
$this->expectException(\InvalidArgumentException::class);
88-
$crawler = $this->createCrawler();
89-
$crawler->add(1);
90-
}
91-
9285
public function testAddMultipleDocumentNode()
9386
{
9487
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)