diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 0b52c2d6..f1c9b92d 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -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'], diff --git a/components/Components/Domain.php b/components/Components/Domain.php index 8acfceb7..c048429b 100644 --- a/components/Components/Domain.php +++ b/components/Components/Domain.php @@ -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) { diff --git a/components/Components/HierarchicalPath.php b/components/Components/HierarchicalPath.php index e5c276d8..820dfc50 100644 --- a/components/Components/HierarchicalPath.php +++ b/components/Components/HierarchicalPath.php @@ -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) { @@ -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) { diff --git a/components/Components/Query.php b/components/Components/Query.php index a01d7115..0ee078d3 100644 --- a/components/Components/Query.php +++ b/components/Components/Query.php @@ -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); diff --git a/components/Modifier.php b/components/Modifier.php index c0995603..988ed572 100644 --- a/components/Modifier.php +++ b/components/Modifier.php @@ -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); @@ -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))); } diff --git a/interfaces/Contracts/DomainHostInterface.php b/interfaces/Contracts/DomainHostInterface.php index 31a3c4a1..66758044 100644 --- a/interfaces/Contracts/DomainHostInterface.php +++ b/interfaces/Contracts/DomainHostInterface.php @@ -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. diff --git a/interfaces/Contracts/SegmentedPathInterface.php b/interfaces/Contracts/SegmentedPathInterface.php index 01645693..fa5a78d2 100644 --- a/interfaces/Contracts/SegmentedPathInterface.php +++ b/interfaces/Contracts/SegmentedPathInterface.php @@ -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. diff --git a/interfaces/QueryString.php b/interfaces/QueryString.php index 9a01c64e..a887668f 100644 --- a/interfaces/QueryString.php +++ b/interfaces/QueryString.php @@ -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) { @@ -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), @@ -153,7 +153,7 @@ public static function parse(Stringable|string|bool|null $query, string $separat * * @return array */ - 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),