From dcec307ab0df390d56a63d4d71d6226bc04b793b Mon Sep 17 00:00:00 2001 From: Yevhen Sidelnyk Date: Fri, 2 May 2025 13:31:39 +0300 Subject: [PATCH 1/2] Unify InvalidUuidException and InvalidUlidException into single InvalidUidException --- ...dException.php => InvalidUidException.php} | 6 +---- .../Uid/Exception/InvalidUuidException.php | 22 ------------------- src/Symfony/Component/Uid/Tests/UlidTest.php | 4 ++-- src/Symfony/Component/Uid/Ulid.php | 4 ++-- src/Symfony/Component/Uid/Uuid.php | 6 ++--- 5 files changed, 8 insertions(+), 34 deletions(-) rename src/Symfony/Component/Uid/Exception/{InvalidUlidException.php => InvalidUidException.php} (60%) delete mode 100644 src/Symfony/Component/Uid/Exception/InvalidUuidException.php diff --git a/src/Symfony/Component/Uid/Exception/InvalidUlidException.php b/src/Symfony/Component/Uid/Exception/InvalidUidException.php similarity index 60% rename from src/Symfony/Component/Uid/Exception/InvalidUlidException.php rename to src/Symfony/Component/Uid/Exception/InvalidUidException.php index cfb42ac5867a7..69e70da4ab5a6 100644 --- a/src/Symfony/Component/Uid/Exception/InvalidUlidException.php +++ b/src/Symfony/Component/Uid/Exception/InvalidUidException.php @@ -11,10 +11,6 @@ namespace Symfony\Component\Uid\Exception; -class InvalidUlidException extends InvalidArgumentException +class InvalidUidException extends InvalidArgumentException { - public function __construct(string $value) - { - parent::__construct(\sprintf('Invalid ULID: "%s".', $value)); - } } diff --git a/src/Symfony/Component/Uid/Exception/InvalidUuidException.php b/src/Symfony/Component/Uid/Exception/InvalidUuidException.php deleted file mode 100644 index 97009412b9c63..0000000000000 --- a/src/Symfony/Component/Uid/Exception/InvalidUuidException.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Uid\Exception; - -class InvalidUuidException extends InvalidArgumentException -{ - public function __construct( - public readonly int $type, - string $value, - ) { - parent::__construct(\sprintf('Invalid UUID%s: "%s".', $type ? 'v'.$type : '', $value)); - } -} diff --git a/src/Symfony/Component/Uid/Tests/UlidTest.php b/src/Symfony/Component/Uid/Tests/UlidTest.php index fe1e15b4cedde..71896510fdb3e 100644 --- a/src/Symfony/Component/Uid/Tests/UlidTest.php +++ b/src/Symfony/Component/Uid/Tests/UlidTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Uid\Exception\InvalidArgumentException; -use Symfony\Component\Uid\Exception\InvalidUlidException; +use Symfony\Component\Uid\Exception\InvalidUidException; use Symfony\Component\Uid\MaxUlid; use Symfony\Component\Uid\NilUlid; use Symfony\Component\Uid\Tests\Fixtures\CustomUlid; @@ -43,7 +43,7 @@ public function testGenerate() public function testWithInvalidUlid() { - $this->expectException(InvalidUlidException::class); + $this->expectException(InvalidUidException::class); $this->expectExceptionMessage('Invalid ULID: "this is not a ulid".'); new Ulid('this is not a ulid'); diff --git a/src/Symfony/Component/Uid/Ulid.php b/src/Symfony/Component/Uid/Ulid.php index 9170d429b0eb7..fbd04e3e0f547 100644 --- a/src/Symfony/Component/Uid/Ulid.php +++ b/src/Symfony/Component/Uid/Ulid.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Uid; use Symfony\Component\Uid\Exception\InvalidArgumentException; -use Symfony\Component\Uid\Exception\InvalidUlidException; +use Symfony\Component\Uid\Exception\InvalidUidException; /** * A ULID is lexicographically sortable and contains a 48-bit timestamp and 80-bit of crypto-random entropy. @@ -39,7 +39,7 @@ public function __construct(?string $ulid = null) $this->uid = $ulid; } else { if (!self::isValid($ulid)) { - throw new InvalidUlidException($ulid); + throw new InvalidUidException(\sprintf('Invalid ULID: "%s".', $ulid)); } $this->uid = strtoupper($ulid); diff --git a/src/Symfony/Component/Uid/Uuid.php b/src/Symfony/Component/Uid/Uuid.php index 66717f2ca1d2e..36e39eb5fd9e6 100644 --- a/src/Symfony/Component/Uid/Uuid.php +++ b/src/Symfony/Component/Uid/Uuid.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Uid; -use Symfony\Component\Uid\Exception\InvalidUuidException; +use Symfony\Component\Uid\Exception\InvalidUidException; /** * @author Grégoire Pineau @@ -41,13 +41,13 @@ public function __construct(string $uuid, bool $checkVariant = false) $type = preg_match('{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di', $uuid) ? (int) $uuid[14] : false; if (false === $type || (static::TYPE ?: $type) !== $type) { - throw new InvalidUuidException(static::TYPE, $uuid); + throw new InvalidUidException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); } $this->uid = strtolower($uuid); if ($checkVariant && !\in_array($this->uid[19], ['8', '9', 'a', 'b'], true)) { - throw new InvalidUuidException(static::TYPE, $uuid); + throw new InvalidUidException(\sprintf('Invalid UUID%s: "%s".', static::TYPE ? 'v'.static::TYPE : '', $uuid)); } } From 2da678b0f60ad9842644c0875f017b64935aeaa5 Mon Sep 17 00:00:00 2001 From: Yevhen Sidelnyk Date: Tue, 6 May 2025 10:36:41 +0300 Subject: [PATCH 2/2] Use InvalidUidException instead of InvalidArgumentException --- src/Symfony/Component/Uid/AbstractUid.php | 20 +++++++------- src/Symfony/Component/Uid/Tests/UlidTest.php | 9 +++--- src/Symfony/Component/Uid/Tests/UuidTest.php | 29 ++++++++++---------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Symfony/Component/Uid/AbstractUid.php b/src/Symfony/Component/Uid/AbstractUid.php index fa35031eaa789..34fe286e73bcb 100644 --- a/src/Symfony/Component/Uid/AbstractUid.php +++ b/src/Symfony/Component/Uid/AbstractUid.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Uid; -use Symfony\Component\Uid\Exception\InvalidArgumentException; +use Symfony\Component\Uid\Exception\InvalidUidException; /** * @author Nicolas Grekas @@ -31,41 +31,41 @@ abstract public static function isValid(string $uid): bool; /** * Creates an AbstractUid from an identifier represented in any of the supported formats. * - * @throws InvalidArgumentException When the passed value is not valid + * @throws InvalidUidException When the passed value is not valid */ abstract public static function fromString(string $uid): static; /** - * @throws InvalidArgumentException When the passed value is not valid + * @throws InvalidUidException When the passed value is not valid */ public static function fromBinary(string $uid): static { if (16 !== \strlen($uid)) { - throw new InvalidArgumentException('Invalid binary uid provided.'); + throw new InvalidUidException('Invalid binary uid provided.'); } return static::fromString($uid); } /** - * @throws InvalidArgumentException When the passed value is not valid + * @throws InvalidUidException When the passed value is not valid */ public static function fromBase58(string $uid): static { if (22 !== \strlen($uid)) { - throw new InvalidArgumentException('Invalid base-58 uid provided.'); + throw new InvalidUidException('Invalid base-58 uid provided.'); } return static::fromString($uid); } /** - * @throws InvalidArgumentException When the passed value is not valid + * @throws InvalidUidException When the passed value is not valid */ public static function fromBase32(string $uid): static { if (26 !== \strlen($uid)) { - throw new InvalidArgumentException('Invalid base-32 uid provided.'); + throw new InvalidUidException('Invalid base-32 uid provided.'); } return static::fromString($uid); @@ -74,12 +74,12 @@ public static function fromBase32(string $uid): static /** * @param string $uid A valid RFC 9562/4122 uid * - * @throws InvalidArgumentException When the passed value is not valid + * @throws InvalidUidException When the passed value is not valid */ public static function fromRfc4122(string $uid): static { if (36 !== \strlen($uid)) { - throw new InvalidArgumentException('Invalid RFC4122 uid provided.'); + throw new InvalidUidException('Invalid RFC4122 uid provided.'); } return static::fromString($uid); diff --git a/src/Symfony/Component/Uid/Tests/UlidTest.php b/src/Symfony/Component/Uid/Tests/UlidTest.php index 71896510fdb3e..490393d419842 100644 --- a/src/Symfony/Component/Uid/Tests/UlidTest.php +++ b/src/Symfony/Component/Uid/Tests/UlidTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Uid\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\Uid\Exception\InvalidArgumentException; use Symfony\Component\Uid\Exception\InvalidUidException; use Symfony\Component\Uid\MaxUlid; use Symfony\Component\Uid\NilUlid; @@ -153,7 +152,7 @@ public function testFromBinary() */ public function testFromBinaryInvalidFormat(string $ulid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); Ulid::fromBinary($ulid); } @@ -180,7 +179,7 @@ public function testFromBase58() */ public function testFromBase58InvalidFormat(string $ulid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); Ulid::fromBase58($ulid); } @@ -207,7 +206,7 @@ public function testFromBase32() */ public function testFromBase32InvalidFormat(string $ulid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); Ulid::fromBase32($ulid); } @@ -234,7 +233,7 @@ public function testFromRfc4122() */ public function testFromRfc4122InvalidFormat(string $ulid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); Ulid::fromRfc4122($ulid); } diff --git a/src/Symfony/Component/Uid/Tests/UuidTest.php b/src/Symfony/Component/Uid/Tests/UuidTest.php index b6986b09ebaa2..00e9817915fe1 100644 --- a/src/Symfony/Component/Uid/Tests/UuidTest.php +++ b/src/Symfony/Component/Uid/Tests/UuidTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Uid\Exception\InvalidArgumentException; +use Symfony\Component\Uid\Exception\InvalidUidException; use Symfony\Component\Uid\MaxUuid; use Symfony\Component\Uid\NilUuid; use Symfony\Component\Uid\Tests\Fixtures\CustomUuid; @@ -36,7 +37,7 @@ class UuidTest extends TestCase */ public function testConstructorWithInvalidUuid(string $uuid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); $this->expectExceptionMessage('Invalid UUID: "'.$uuid.'".'); Uuid::fromString($uuid); @@ -59,7 +60,7 @@ public function testInvalidVariant(string $uuid) $uuid = (string) $uuid; $class = Uuid::class.'V'.$uuid[14]; - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); $this->expectExceptionMessage('Invalid UUIDv'.$uuid[14].': "'.$uuid.'".'); new $class($uuid); @@ -380,11 +381,11 @@ public function testFromBinary() /** * @dataProvider provideInvalidBinaryFormat */ - public function testFromBinaryInvalidFormat(string $ulid) + public function testFromBinaryInvalidFormat(string $uuid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); - Uuid::fromBinary($ulid); + Uuid::fromBinary($uuid); } public static function provideInvalidBinaryFormat(): array @@ -407,11 +408,11 @@ public function testFromBase58() /** * @dataProvider provideInvalidBase58Format */ - public function testFromBase58InvalidFormat(string $ulid) + public function testFromBase58InvalidFormat(string $uuid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); - Uuid::fromBase58($ulid); + Uuid::fromBase58($uuid); } public static function provideInvalidBase58Format(): array @@ -434,11 +435,11 @@ public function testFromBase32() /** * @dataProvider provideInvalidBase32Format */ - public function testFromBase32InvalidFormat(string $ulid) + public function testFromBase32InvalidFormat(string $uuid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); - Uuid::fromBase32($ulid); + Uuid::fromBase32($uuid); } public static function provideInvalidBase32Format(): array @@ -461,11 +462,11 @@ public function testFromRfc4122() /** * @dataProvider provideInvalidRfc4122Format */ - public function testFromRfc4122InvalidFormat(string $ulid) + public function testFromRfc4122InvalidFormat(string $uuid) { - $this->expectException(InvalidArgumentException::class); + $this->expectException(InvalidUidException::class); - Uuid::fromRfc4122($ulid); + Uuid::fromRfc4122($uuid); } public static function provideInvalidRfc4122Format(): array pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy