Skip to content

Commit dc7ff23

Browse files
committed
use constructor property promotion
1 parent 01ce817 commit dc7ff23

10 files changed

+44
-56
lines changed

AbstractUriElement.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ abstract class AbstractUriElement
2020
{
2121
protected \DOMElement $node;
2222
protected ?string $method;
23-
protected ?string $currentUri;
2423

2524
/**
2625
* @param \DOMElement $node A \DOMElement instance
@@ -29,11 +28,13 @@ abstract class AbstractUriElement
2928
*
3029
* @throws \InvalidArgumentException if the node is not a link
3130
*/
32-
public function __construct(\DOMElement $node, ?string $currentUri = null, ?string $method = 'GET')
33-
{
31+
public function __construct(
32+
\DOMElement $node,
33+
protected ?string $currentUri = null,
34+
?string $method = 'GET',
35+
) {
3436
$this->setNode($node);
3537
$this->method = $method ? strtoupper($method) : null;
36-
$this->currentUri = $currentUri;
3738

3839
$elementUriIsRelative = null === parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
3940
$baseUriIsAbsolute = null !== $this->currentUri && \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);

Crawler.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
class Crawler implements \Countable, \IteratorAggregate
2525
{
26-
protected ?string $uri;
27-
2826
/**
2927
* The default namespace prefix to be used with XPath and CSS expressions.
3028
*/
@@ -60,9 +58,12 @@ class Crawler implements \Countable, \IteratorAggregate
6058
/**
6159
* @param \DOMNodeList|\DOMNode|\DOMNode[]|string|null $node A Node to use as the base for the crawling
6260
*/
63-
public function __construct(\DOMNodeList|\DOMNode|array|string|null $node = null, ?string $uri = null, ?string $baseHref = null, bool $useHtml5Parser = true)
64-
{
65-
$this->uri = $uri;
61+
public function __construct(
62+
\DOMNodeList|\DOMNode|array|string|null $node = null,
63+
protected ?string $uri = null,
64+
?string $baseHref = null,
65+
bool $useHtml5Parser = true,
66+
) {
6667
$this->baseHref = $baseHref ?: $uri;
6768
$this->html5Parser = $useHtml5Parser ? new HTML5(['disable_html_ns' => true]) : null;
6869
$this->cachedNamespaces = new \ArrayObject();

Field/FormField.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
abstract class FormField
2020
{
21-
protected \DOMElement $node;
2221
protected string $name;
2322
protected string|array|null $value = null;
2423
protected \DOMDocument $document;
@@ -28,9 +27,9 @@ abstract class FormField
2827
/**
2928
* @param \DOMElement $node The node associated with this field
3029
*/
31-
public function __construct(\DOMElement $node)
32-
{
33-
$this->node = $node;
30+
public function __construct(
31+
protected \DOMElement $node,
32+
) {
3433
$this->name = $node->getAttribute('name');
3534
$this->xpath = new \DOMXPath($node->ownerDocument);
3635

Form.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Form extends Link implements \ArrayAccess
2323
{
2424
private \DOMElement $button;
2525
private FormFieldRegistry $fields;
26-
private ?string $baseHref;
2726

2827
/**
2928
* @param \DOMElement $node A \DOMElement instance
@@ -33,10 +32,13 @@ class Form extends Link implements \ArrayAccess
3332
*
3433
* @throws \LogicException if the node is not a button inside a form tag
3534
*/
36-
public function __construct(\DOMElement $node, ?string $currentUri = null, ?string $method = null, ?string $baseHref = null)
37-
{
35+
public function __construct(
36+
\DOMElement $node,
37+
?string $currentUri = null,
38+
?string $method = null,
39+
private ?string $baseHref = null,
40+
) {
3841
parent::__construct($node, $currentUri, $method);
39-
$this->baseHref = $baseHref;
4042

4143
$this->initialize();
4244
}

Test/Constraint/CrawlerAnySelectorTextContains.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
final class CrawlerAnySelectorTextContains extends Constraint
1818
{
19-
private string $selector;
20-
private string $expectedText;
2119
private bool $hasNode = false;
2220

23-
public function __construct(string $selector, string $expectedText)
24-
{
25-
$this->selector = $selector;
26-
$this->expectedText = $expectedText;
21+
public function __construct(
22+
private string $selector,
23+
private string $expectedText,
24+
) {
2725
}
2826

2927
public function toString(): string

Test/Constraint/CrawlerAnySelectorTextSame.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
final class CrawlerAnySelectorTextSame extends Constraint
1818
{
19-
private string $selector;
20-
private string $expectedText;
21-
22-
public function __construct(string $selector, string $expectedText)
23-
{
24-
$this->selector = $selector;
25-
$this->expectedText = $expectedText;
19+
public function __construct(
20+
private string $selector,
21+
private string $expectedText,
22+
) {
2623
}
2724

2825
public function toString(): string

Test/Constraint/CrawlerSelectorAttributeValueSame.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
final class CrawlerSelectorAttributeValueSame extends Constraint
1818
{
19-
private string $selector;
20-
private string $attribute;
21-
private string $expectedText;
22-
23-
public function __construct(string $selector, string $attribute, string $expectedText)
24-
{
25-
$this->selector = $selector;
26-
$this->attribute = $attribute;
27-
$this->expectedText = $expectedText;
19+
public function __construct(
20+
private string $selector,
21+
private string $attribute,
22+
private string $expectedText,
23+
) {
2824
}
2925

3026
public function toString(): string

Test/Constraint/CrawlerSelectorExists.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
final class CrawlerSelectorExists extends Constraint
1818
{
19-
private string $selector;
2019

21-
public function __construct(string $selector)
22-
{
23-
$this->selector = $selector;
20+
public function __construct(
21+
private string $selector,
22+
) {
2423
}
2524

2625
public function toString(): string

Test/Constraint/CrawlerSelectorTextContains.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616

1717
final class CrawlerSelectorTextContains extends Constraint
1818
{
19-
private string $selector;
20-
private string $expectedText;
2119
private bool $hasNode = false;
2220
private string $nodeText;
2321

24-
public function __construct(string $selector, string $expectedText)
25-
{
26-
$this->selector = $selector;
27-
$this->expectedText = $expectedText;
22+
public function __construct(
23+
private string $selector,
24+
private string $expectedText,
25+
) {
2826
}
2927

3028
public function toString(): string

Test/Constraint/CrawlerSelectorTextSame.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
final class CrawlerSelectorTextSame extends Constraint
1818
{
19-
private string $selector;
20-
private string $expectedText;
21-
22-
public function __construct(string $selector, string $expectedText)
23-
{
24-
$this->selector = $selector;
25-
$this->expectedText = $expectedText;
19+
public function __construct(
20+
private string $selector,
21+
private string $expectedText,
22+
) {
2623
}
2724

2825
public function toString(): string

0 commit comments

Comments
 (0)