diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 24a62d81..4f55b144 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,5 +1,7 @@ setParallelConfig(ParallelConfigFactory::detect()) ->setRules([ '@PSR12' => true, 'array_syntax' => ['syntax' => 'short'], diff --git a/components/CHANGELOG.md b/components/CHANGELOG.md index ee703ede..79ebe60d 100644 --- a/components/CHANGELOG.md +++ b/components/CHANGELOG.md @@ -2,6 +2,24 @@ All Notable changes to `League\Uri\Components` will be documented in this file +## [Next](https://github.com/thephpleague/uri-components/compare/7.4.1...master) - TBD + +### Added + +- `UrlSearchParams::uniqueKeyCount` + +### Fixed + +- None + +### Deprecated + +- None + +### Removed + +- None + ## [7.4.1](https://github.com/thephpleague/uri-components/compare/7.4.0...7.4.1) - 2024-02-23 ### Added diff --git a/components/Components/HierarchicalPath.php b/components/Components/HierarchicalPath.php index 820dfc50..b915e176 100644 --- a/components/Components/HierarchicalPath.php +++ b/components/Components/HierarchicalPath.php @@ -111,8 +111,7 @@ public static function fromAbsolute(string ...$segments): self */ private static function fromSegments(int $pathType, array $segments): self { - $pathSegments = array_map(fn (Stringable|string $segment): string => (string) $segment, $segments); - $path = implode(self::SEPARATOR, $pathSegments); + $path = implode(self::SEPARATOR, $segments); return match (true) { self::IS_RELATIVE === $pathType => new self(ltrim($path, self::SEPARATOR)), diff --git a/components/Components/URLSearchParams.php b/components/Components/URLSearchParams.php index 5e062295..706ad279 100644 --- a/components/Components/URLSearchParams.php +++ b/components/Components/URLSearchParams.php @@ -375,6 +375,18 @@ public function isEmpty(): bool return 0 === $this->size(); } + /** + * Returns the total number of distinct search parameter keys. + */ + public function uniqueKeyCount(): int + { + return count( + array_count_values( + array_column([...$this->pairs], 0) + ) + ); + } + /** * Returns the total number of search parameter entries. */ diff --git a/components/Components/URLSearchParamsTest.php b/components/Components/URLSearchParamsTest.php index f20e8399..e9994e72 100644 --- a/components/Components/URLSearchParamsTest.php +++ b/components/Components/URLSearchParamsTest.php @@ -630,18 +630,22 @@ public function testSizeWithDeletionMethodAndBehaviour(): void self::assertCount(3, $params); self::assertTrue($params->isNotEmpty()); self::assertFalse($params->isEmpty()); + self::assertSame(2, $params->uniqueKeyCount()); $params->delete('a'); self::assertCount(1, $params); + self::assertSame(1, $params->uniqueKeyCount()); } public function testSizeWithAdditionMethodAndBehaviour(): void { $params = new URLSearchParams('a=1&b=2&a=3'); self::assertCount(3, $params); + self::assertSame(2, $params->uniqueKeyCount()); $params->append('b', '4'); self::assertCount(4, $params); + self::assertSame(2, $params->uniqueKeyCount()); } public function testSizeWithEmptyInstance(): void @@ -650,6 +654,7 @@ public function testSizeWithEmptyInstance(): void self::assertCount(0, $params); self::assertFalse($params->isNotEmpty()); self::assertTrue($params->isEmpty()); + self::assertSame(0, $params->uniqueKeyCount()); } public function testBasicHasMethod(): void diff --git a/composer.json b/composer.json index 2de2f147..9db0ee34 100644 --- a/composer.json +++ b/composer.json @@ -28,19 +28,19 @@ "ext-fileinfo": "*", "ext-gmp": "*", "ext-intl": "*", - "friendsofphp/php-cs-fixer": "^3.53.0", + "friendsofphp/php-cs-fixer": "^3.57.2", "guzzlehttp/psr7": "^2.6.2", "laminas/laminas-diactoros": "^3.3.1", "nyholm/psr7": "^1.8.1", "phpbench/phpbench": "^1.2.15", - "phpstan/phpstan": "^1.10.66", - "phpstan/phpstan-deprecation-rules": "^1.1.4", - "phpstan/phpstan-phpunit": "^1.3.16", - "phpstan/phpstan-strict-rules": "^1.5.3", - "phpunit/phpunit": "^10.5.17 || ^11.1.1", - "psr/http-factory": "^1.0.2", + "phpstan/phpstan": "^1.11.2", + "phpstan/phpstan-deprecation-rules": "^1.2.0", + "phpstan/phpstan-phpunit": "^1.4.0", + "phpstan/phpstan-strict-rules": "^1.6.0", + "phpunit/phpunit": "^10.5.17 || ^11.1.3", + "psr/http-factory": "^1.1.0", "psr/http-message": "^1.1.0 || ^2.0", - "symfony/var-dumper": "^6.4.6", + "symfony/var-dumper": "^6.4.7", "uri-templates/uritemplate-test": "dev-master" }, "repositories": [ diff --git a/docs/components/7.0/urlsearchparams.md b/docs/components/7.0/urlsearchparams.md index 0c441e66..c2cfb860 100644 --- a/docs/components/7.0/urlsearchparams.md +++ b/docs/components/7.0/urlsearchparams.md @@ -90,6 +90,7 @@ While the class implements all the methods define in the RFC, the following meth - `URLSearchParams::isEmpty` - `URLSearchParams::isNotEmpty` +- `URLSearchParams::uniqueKeyCount` new in version `7.5.0` ~~~php use League\Uri\Components\URLSearchParams; @@ -104,6 +105,7 @@ $params->has('foo', 'bar'); //returns true $params->has('foo', 'toto'); //returns false (the second parameter is the value of the pair) count($params); //returns 3 $params->size(); //returns 3 +$params->uniqueKeyCount(); //returns 2 $params->delete('foo'); count($params); //returns 1 (because all the pairs which contains foo have been removed) $params->set('aha', true); diff --git a/phpstan.neon b/phpstan.neon index 7e2edea9..ac1c17bb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,6 +15,6 @@ parameters: path: interfaces/IPv4/NativeCalculator.php - message: '#function gmp_(.*)? expects (GMP|int)#' path: interfaces/IPv4/GMPCalculator.php + - identifier: missingType.iterableValue reportUnmatchedIgnoredErrors: true treatPhpDocTypesAsCertain: false - checkMissingIterableValueType: false