Skip to content

Commit

Permalink
Handles PHP8.4 nullable type deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Mar 22, 2024
1 parent 7811195 commit 521e5ed
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'no_superfluous_phpdoc_tags' => true,
'no_trailing_comma_in_singleline' => true,
'no_unused_imports' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_align' => ['align' => 'left'],
Expand Down
2 changes: 1 addition & 1 deletion components/Components/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function withRootLabel(): DomainHostInterface
};
}

public function slice(int $offset, int $length = null): self
public function slice(int $offset, ?int $length = null): self
{
$nbLabels = count($this->labels);
if ($offset < -$nbLabels || $offset > $nbLabels) {
Expand Down
4 changes: 2 additions & 2 deletions components/Components/HierarchicalPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function withoutSegment(int ...$keys): SegmentedPathInterface
return new self($path);
}

public function slice(int $offset, int $length = null): self
public function slice(int $offset, ?int $length = null): self
{
$nbSegments = count($this->segments);
if ($offset < -$nbSegments || $offset > $nbSegments) {
Expand Down Expand Up @@ -425,7 +425,7 @@ public function withExtension(Stringable|string $extension): SegmentedPathInterf
/**
* Creates a new basename with a new extension.
*/
private function buildBasename(string $extension, string $ext, string $param = null): string
private function buildBasename(string $extension, string $ext, ?string $param = null): string
{
$length = strrpos($ext, '.'.pathinfo($ext, PATHINFO_EXTENSION));
if (false !== $length) {
Expand Down
2 changes: 1 addition & 1 deletion components/Components/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class Query extends Component implements QueryInterface
/**
* Returns a new instance.
*/
private function __construct(Stringable|string|null $query, Converter $converter = null)
private function __construct(Stringable|string|null $query, ?Converter $converter = null)
{
$converter ??= Converter::fromRFC3986();
$this->pairs = QueryString::parseFromValue($query, $converter);
Expand Down
4 changes: 2 additions & 2 deletions components/Modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function removeRootLabel(): static
/**
* Slice the host from the URI.
*/
public function sliceLabels(int $offset, int $length = null): static
public function sliceLabels(int $offset, ?int $length = null): static
{
$currentHost = $this->uri->getHost();
$host = Domain::new($currentHost)->slice($offset, $length);
Expand Down Expand Up @@ -702,7 +702,7 @@ public function replaceSegment(int $offset, Stringable|string $segment): static
/**
* Slice the host from the URI.
*/
public function sliceSegments(int $offset, int $length = null): static
public function sliceSegments(int $offset, ?int $length = null): static
{
return new static(static::normalizePath($this->uri, HierarchicalPath::fromUri($this->uri)->slice($offset, $length)));
}
Expand Down
2 changes: 1 addition & 1 deletion interfaces/Contracts/DomainHostInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function append(Stringable|string $label): self;
*
* If $length is null it returns all elements from $offset to the end of the Domain.
*/
public function slice(int $offset, int $length = null): self;
public function slice(int $offset, ?int $length = null): self;

/**
* Returns an instance with its Root label.
Expand Down
2 changes: 1 addition & 1 deletion interfaces/Contracts/SegmentedPathInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function append(Stringable|string $segment): self;
*
* If $length is null it returns all elements from $offset to the end of the Path.
*/
public function slice(int $offset, int $length = null): self;
public function slice(int $offset, ?int $length = null): self;

/**
* Prepends a segment to the path.
Expand Down
6 changes: 3 additions & 3 deletions interfaces/QueryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function build(iterable $pairs, string $separator = '&', int $encT
* @throws SyntaxError If the encoding type is invalid
* @throws SyntaxError If a pair is invalid
*/
public static function buildFromPairs(iterable $pairs, Converter $converter = null): ?string
public static function buildFromPairs(iterable $pairs, ?Converter $converter = null): ?string
{
$keyValuePairs = [];
foreach ($pairs as $pair) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public static function extract(Stringable|string|bool|null $query, string $separ
*
* @throws SyntaxError
*/
public static function extractFromValue(Stringable|string|bool|null $query, Converter $converter = null): array
public static function extractFromValue(Stringable|string|bool|null $query, ?Converter $converter = null): array
{
return self::convert(self::decodePairs(
($converter ?? Converter::fromRFC3986())->toPairs($query),
Expand Down Expand Up @@ -153,7 +153,7 @@ public static function parse(Stringable|string|bool|null $query, string $separat
*
* @return array<int, array{0:string, 1:string|null}>
*/
public static function parseFromValue(Stringable|string|bool|null $query, Converter $converter = null): array
public static function parseFromValue(Stringable|string|bool|null $query, ?Converter $converter = null): array
{
return self::decodePairs(
($converter ?? Converter::fromRFC3986())->toPairs($query),
Expand Down

0 comments on commit 521e5ed

Please sign in to comment.