Skip to content

Commit

Permalink
Merge pull request #551 from emteknetnz/php84-implicit-nullable
Browse files Browse the repository at this point in the history
Make nullable parameters explicity nullable for PHP 8.4
  • Loading branch information
oscarotero authored Dec 4, 2024
2 parents a63e149 + e1dcf77 commit e969571
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static function buildQuery(string $startQuery, array $attributes): strin
/**
* Select a element in the dom
*/
public function select(string $query, array $attributes = null, DOMNode $context = null): QueryResult
public function select(string $query, ?array $attributes = null, ?DOMNode $context = null): QueryResult
{
if (!empty($attributes)) {
$query = self::buildQuery($query, $attributes);
Expand All @@ -119,7 +119,7 @@ public function select(string $query, array $attributes = null, DOMNode $context
/**
* Select a element in the dom using a css selector
*/
public function selectCss(string $query, DOMNode $context = null): QueryResult
public function selectCss(string $query, ?DOMNode $context = null): QueryResult
{
return $this->select(self::cssToXpath($query), null, $context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Embed
private Crawler $crawler;
private ExtractorFactory $extractorFactory;

public function __construct(Crawler $crawler = null, ExtractorFactory $extractorFactory = null)
public function __construct(?Crawler $crawler = null, ?ExtractorFactory $extractorFactory = null)
{
$this->crawler = $crawler ?: new Crawler();
$this->extractorFactory = $extractorFactory ?: new ExtractorFactory();
Expand Down
2 changes: 1 addition & 1 deletion src/EmbedCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EmbedCode implements JsonSerializable
public ?int $height;
public ?float $ratio = null;

public function __construct(string $html, int $width = null, int $height = null)
public function __construct(string $html, ?int $width = null, ?int $height = null)
{
$this->html = $html;
$this->width = $width;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Crawler implements ClientInterface, RequestFactoryInterface, UriFactoryInt
'Cache-Control' => 'max-age=0',
];

public function __construct(ClientInterface $client = null, RequestFactoryInterface $requestFactory = null, UriFactoryInterface $uriFactory = null)
public function __construct(?ClientInterface $client = null, ?RequestFactoryInterface $requestFactory = null, ?UriFactoryInterface $uriFactory = null)
{
$this->client = $client ?: new CurlClient();
$this->requestFactory = $requestFactory ?: FactoryDiscovery::getRequestFactory();
Expand Down
2 changes: 1 addition & 1 deletion src/Http/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CurlClient implements ClientInterface
private ResponseFactoryInterface $responseFactory;
private array $settings = [];

public function __construct(ResponseFactoryInterface $responseFactory = null)
public function __construct(?ResponseFactoryInterface $responseFactory = null)
{
$this->responseFactory = $responseFactory ?: FactoryDiscovery::getResponseFactory();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/CurlDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function fetch(array $settings, ResponseFactoryInterface $response
);
}

private function __construct(array $settings, RequestInterface $request, StreamFactoryInterface $streamFactory = null)
private function __construct(array $settings, RequestInterface $request, ?StreamFactoryInterface $streamFactory = null)
{
$this->request = $request;
$this->curl = curl_init((string) $request->getUri());
Expand Down
2 changes: 1 addition & 1 deletion src/LinkedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getAll()
return $this->allData;
}

private function getGraph(string $name = null): ?GraphInterface
private function getGraph(?string $name = null): ?GraphInterface
{
if (!isset($this->document)) {
try {
Expand Down
12 changes: 6 additions & 6 deletions src/QueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function filter(Closure $callback): self
return $this;
}

public function get(string $attribute = null)
public function get(?string $attribute = null)
{
$node = $this->node();

Expand All @@ -48,7 +48,7 @@ public function get(string $attribute = null)
return $attribute ? self::getAttribute($node, $attribute) : $node->nodeValue;
}

public function getAll(string $attribute = null): array
public function getAll(?string $attribute = null): array
{
$nodes = $this->nodes();

Expand All @@ -60,26 +60,26 @@ public function getAll(string $attribute = null): array
);
}

public function str(string $attribute = null): ?string
public function str(?string $attribute = null): ?string
{
$value = $this->get($attribute);

return $value ? clean($value) : null;
}

public function strAll(string $attribute = null): array
public function strAll(?string $attribute = null): array
{
return array_filter(array_map(fn ($value) => clean($value), $this->getAll($attribute)));
}

public function int(string $attribute = null): ?int
public function int(?string $attribute = null): ?int
{
$value = $this->get($attribute);

return $value ? (int) $value : null;
}

public function url(string $attribute = null): ?UriInterface
public function url(?string $attribute = null): ?UriInterface
{
$value = $this->get($attribute);

Expand Down

0 comments on commit e969571

Please sign in to comment.