← All changes
|
includes/sdk/google/ramsey/uuid/src/Lazy/LazyUuidFromString.php
+125
-224
1.2.13
→
1.4.2
View file →
| @@ -9,20 +9,20 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <[email protected]> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Uuid\Lazy; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Lazy; | |
| 14 | 14 | |
| 15 | 15 | use DateTimeInterface; |
| 16 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\NumberConverterInterface; | |
| 17 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Exception\UnsupportedOperationException; | |
| 18 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Fields\FieldsInterface; | |
| 19 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Nonstandard\UuidV6; | |
| 20 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Rfc4122\UuidV1; | |
| 21 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Type\Hexadecimal; | |
| 22 | -use Dudlewebs\WPMCS\Ramsey\Uuid\Type\Integer as IntegerObject; | |
| 23 | -use Dudlewebs\WPMCS\Ramsey\Uuid\UuidFactory; | |
| 24 | -use Dudlewebs\WPMCS\Ramsey\Uuid\UuidInterface; | |
| 16 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\NumberConverterInterface; | |
| 17 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Exception\UnsupportedOperationException; | |
| 18 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Fields\FieldsInterface; | |
| 19 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\UuidV1; | |
| 20 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\UuidV6; | |
| 21 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Type\Hexadecimal; | |
| 22 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Type\Integer as IntegerObject; | |
| 23 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\UuidFactory; | |
| 24 | +use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\UuidInterface; | |
| 25 | 25 | use ValueError; |
| 26 | 26 | use function assert; |
| 27 | 27 | use function bin2hex; |
| 28 | 28 | use function hex2bin; |
| @@ -30,56 +30,44 @@ | ||
| 30 | 30 | use function str_replace; |
| 31 | 31 | use function substr; |
| 32 | 32 | /** |
| 33 | 33 | * Lazy version of a UUID: its format has not been determined yet, so it is mostly only usable for string/bytes |
| 34 | - * conversion. This object optimizes instantiation, serialization and string conversion time, at the cost of | |
| 35 | - * increased overhead for more advanced UUID operations. | |
| 34 | + * conversion. This object optimizes instantiation, serialization and string conversion time, at the cost of increased | |
| 35 | + * overhead for more advanced UUID operations. | |
| 36 | 36 | * |
| 37 | - * @internal this type is used internally for performance reasons, and is not supposed to be directly referenced | |
| 38 | - * in consumer libraries. | |
| 37 | + * > [!NOTE] | |
| 38 | + * > The {@see FieldsInterface} does not declare methods that deprecated API relies upon: the API has been ported from | |
| 39 | + * > the {@see \Ramsey\Uuid\Uuid} definition, and is deprecated anyway. | |
| 39 | 40 | * |
| 40 | - * @psalm-immutable | |
| 41 | + * > [!NOTE] | |
| 42 | + * > The deprecated API from {@see \Ramsey\Uuid\Uuid} is in use here (on purpose): it will be removed once the | |
| 43 | + * > deprecated API is gone from this class too. | |
| 41 | 44 | * |
| 42 | - * Note: the {@see FieldsInterface} does not declare methods that deprecated API | |
| 43 | - * relies upon: the API has been ported from the {@see \Ramsey\Uuid\Uuid} definition, | |
| 44 | - * and is deprecated anyway. | |
| 45 | - * Note: the deprecated API from {@see \Ramsey\Uuid\Uuid} is in use here (on purpose): it will be removed | |
| 46 | - * once the deprecated API is gone from this class too. | |
| 47 | - * | |
| 48 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 49 | - * @psalm-suppress DeprecatedMethod | |
| 45 | + * @internal this type is used internally for performance reasons and is not supposed to be directly referenced in consumer libraries. | |
| 50 | 46 | */ |
| 51 | 47 | final class LazyUuidFromString implements UuidInterface |
| 52 | 48 | { |
| 53 | - public const VALID_REGEX = '/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/ms'; | |
| 49 | + public const VALID_REGEX = '/\\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\z/ms'; | |
| 50 | + private ?UuidInterface $unwrapped = null; | |
| 54 | 51 | /** |
| 55 | - * @var string | |
| 56 | - * @psalm-var non-empty-string | |
| 52 | + * @param non-empty-string $uuid | |
| 57 | 53 | */ |
| 58 | - private $uuid; | |
| 59 | - /** @var UuidInterface|null */ | |
| 60 | - private $unwrapped; | |
| 61 | - /** @psalm-param non-empty-string $uuid */ | |
| 62 | - public function __construct(string $uuid) | |
| 54 | + public function __construct(private string $uuid) | |
| 63 | 55 | { |
| 64 | - $this->uuid = $uuid; | |
| 65 | 56 | } |
| 66 | - /** @psalm-pure */ | |
| 67 | - public static function fromBytes(string $bytes): self | |
| 57 | + public static function fromBytes(string $bytes) : self | |
| 68 | 58 | { |
| 69 | 59 | $base16Uuid = bin2hex($bytes); |
| 70 | 60 | return new self(substr($base16Uuid, 0, 8) . '-' . substr($base16Uuid, 8, 4) . '-' . substr($base16Uuid, 12, 4) . '-' . substr($base16Uuid, 16, 4) . '-' . substr($base16Uuid, 20, 12)); |
| 71 | 61 | } |
| 72 | - public function serialize(): string | |
| 62 | + public function serialize() : string | |
| 73 | 63 | { |
| 74 | 64 | return $this->uuid; |
| 75 | 65 | } |
| 76 | 66 | /** |
| 77 | - * @return array{string: string} | |
| 78 | - * | |
| 79 | - * @psalm-return array{string: non-empty-string} | |
| 67 | + * @return array{string: non-empty-string} | |
| 80 | 68 | */ |
| 81 | - public function __serialize(): array | |
| 69 | + public function __serialize() : array | |
| 82 | 70 | { |
| 83 | 71 | return ['string' => $this->uuid]; |
| 84 | 72 | } |
| 85 | 73 | /** |
| @@ -84,22 +72,18 @@ | ||
| 84 | 72 | } |
| 85 | 73 | /** |
| 86 | 74 | * {@inheritDoc} |
| 87 | 75 | * |
| 88 | - * @param string $serialized | |
| 89 | - * | |
| 90 | - * @psalm-param non-empty-string $serialized | |
| 76 | + * @param non-empty-string $data | |
| 91 | 77 | */ |
| 92 | - public function unserialize($serialized): void | |
| 78 | + public function unserialize(string $data) : void | |
| 93 | 79 | { |
| 94 | - $this->uuid = $serialized; | |
| 80 | + $this->uuid = $data; | |
| 95 | 81 | } |
| 96 | 82 | /** |
| 97 | - * @param array{string: string} $data | |
| 98 | - * | |
| 99 | - * @psalm-param array{string: non-empty-string} $data | |
| 83 | + * @param array{string?: non-empty-string} $data | |
| 100 | 84 | */ |
| 101 | - public function __unserialize(array $data): void | |
| 85 | + public function __unserialize(array $data) : void | |
| 102 | 86 | { |
| 103 | 87 | // @codeCoverageIgnoreStart |
| 104 | 88 | if (!isset($data['string'])) { |
| 105 | 89 | throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__)); |
| @@ -106,97 +90,80 @@ | ||
| 106 | 90 | } |
| 107 | 91 | // @codeCoverageIgnoreEnd |
| 108 | 92 | $this->unserialize($data['string']); |
| 109 | 93 | } |
| 110 | - /** @psalm-suppress DeprecatedMethod */ | |
| 111 | - public function getNumberConverter(): NumberConverterInterface | |
| 94 | + public function getNumberConverter() : NumberConverterInterface | |
| 112 | 95 | { |
| 113 | 96 | return ($this->unwrapped ?? $this->unwrap())->getNumberConverter(); |
| 114 | 97 | } |
| 115 | 98 | /** |
| 116 | - * {@inheritDoc} | |
| 117 | - * | |
| 118 | - * @psalm-suppress DeprecatedMethod | |
| 99 | + * @inheritDoc | |
| 119 | 100 | */ |
| 120 | - public function getFieldsHex(): array | |
| 101 | + public function getFieldsHex() : array | |
| 121 | 102 | { |
| 122 | 103 | return ($this->unwrapped ?? $this->unwrap())->getFieldsHex(); |
| 123 | 104 | } |
| 124 | - /** @psalm-suppress DeprecatedMethod */ | |
| 125 | - public function getClockSeqHiAndReservedHex(): string | |
| 105 | + public function getClockSeqHiAndReservedHex() : string | |
| 126 | 106 | { |
| 127 | 107 | return ($this->unwrapped ?? $this->unwrap())->getClockSeqHiAndReservedHex(); |
| 128 | 108 | } |
| 129 | - /** @psalm-suppress DeprecatedMethod */ | |
| 130 | - public function getClockSeqLowHex(): string | |
| 109 | + public function getClockSeqLowHex() : string | |
| 131 | 110 | { |
| 132 | 111 | return ($this->unwrapped ?? $this->unwrap())->getClockSeqLowHex(); |
| 133 | 112 | } |
| 134 | - /** @psalm-suppress DeprecatedMethod */ | |
| 135 | - public function getClockSequenceHex(): string | |
| 113 | + public function getClockSequenceHex() : string | |
| 136 | 114 | { |
| 137 | 115 | return ($this->unwrapped ?? $this->unwrap())->getClockSequenceHex(); |
| 138 | 116 | } |
| 139 | - /** @psalm-suppress DeprecatedMethod */ | |
| 140 | - public function getDateTime(): DateTimeInterface | |
| 117 | + public function getDateTime() : DateTimeInterface | |
| 141 | 118 | { |
| 142 | 119 | return ($this->unwrapped ?? $this->unwrap())->getDateTime(); |
| 143 | 120 | } |
| 144 | - /** @psalm-suppress DeprecatedMethod */ | |
| 145 | - public function getLeastSignificantBitsHex(): string | |
| 121 | + public function getLeastSignificantBitsHex() : string | |
| 146 | 122 | { |
| 147 | 123 | return ($this->unwrapped ?? $this->unwrap())->getLeastSignificantBitsHex(); |
| 148 | 124 | } |
| 149 | - /** @psalm-suppress DeprecatedMethod */ | |
| 150 | - public function getMostSignificantBitsHex(): string | |
| 125 | + public function getMostSignificantBitsHex() : string | |
| 151 | 126 | { |
| 152 | 127 | return ($this->unwrapped ?? $this->unwrap())->getMostSignificantBitsHex(); |
| 153 | 128 | } |
| 154 | - /** @psalm-suppress DeprecatedMethod */ | |
| 155 | - public function getNodeHex(): string | |
| 129 | + public function getNodeHex() : string | |
| 156 | 130 | { |
| 157 | 131 | return ($this->unwrapped ?? $this->unwrap())->getNodeHex(); |
| 158 | 132 | } |
| 159 | - /** @psalm-suppress DeprecatedMethod */ | |
| 160 | - public function getTimeHiAndVersionHex(): string | |
| 133 | + public function getTimeHiAndVersionHex() : string | |
| 161 | 134 | { |
| 162 | 135 | return ($this->unwrapped ?? $this->unwrap())->getTimeHiAndVersionHex(); |
| 163 | 136 | } |
| 164 | - /** @psalm-suppress DeprecatedMethod */ | |
| 165 | - public function getTimeLowHex(): string | |
| 137 | + public function getTimeLowHex() : string | |
| 166 | 138 | { |
| 167 | 139 | return ($this->unwrapped ?? $this->unwrap())->getTimeLowHex(); |
| 168 | 140 | } |
| 169 | - /** @psalm-suppress DeprecatedMethod */ | |
| 170 | - public function getTimeMidHex(): string | |
| 141 | + public function getTimeMidHex() : string | |
| 171 | 142 | { |
| 172 | 143 | return ($this->unwrapped ?? $this->unwrap())->getTimeMidHex(); |
| 173 | 144 | } |
| 174 | - /** @psalm-suppress DeprecatedMethod */ | |
| 175 | - public function getTimestampHex(): string | |
| 145 | + public function getTimestampHex() : string | |
| 176 | 146 | { |
| 177 | 147 | return ($this->unwrapped ?? $this->unwrap())->getTimestampHex(); |
| 178 | 148 | } |
| 179 | - /** @psalm-suppress DeprecatedMethod */ | |
| 180 | - public function getUrn(): string | |
| 149 | + public function getUrn() : string | |
| 181 | 150 | { |
| 182 | 151 | return ($this->unwrapped ?? $this->unwrap())->getUrn(); |
| 183 | 152 | } |
| 184 | - /** @psalm-suppress DeprecatedMethod */ | |
| 185 | - public function getVariant(): ?int | |
| 153 | + public function getVariant() : ?int | |
| 186 | 154 | { |
| 187 | 155 | return ($this->unwrapped ?? $this->unwrap())->getVariant(); |
| 188 | 156 | } |
| 189 | - /** @psalm-suppress DeprecatedMethod */ | |
| 190 | - public function getVersion(): ?int | |
| 157 | + public function getVersion() : ?int | |
| 191 | 158 | { |
| 192 | 159 | return ($this->unwrapped ?? $this->unwrap())->getVersion(); |
| 193 | 160 | } |
| 194 | - public function compareTo(UuidInterface $other): int | |
| 161 | + public function compareTo(UuidInterface $other) : int | |
| 195 | 162 | { |
| 196 | 163 | return ($this->unwrapped ?? $this->unwrap())->compareTo($other); |
| 197 | 164 | } |
| 198 | - public function equals(?object $other): bool | |
| 165 | + public function equals(?object $other) : bool | |
| 199 | 166 | { |
| 200 | 167 | if (!$other instanceof UuidInterface) { |
| 201 | 168 | return \false; |
| 202 | 169 | } |
| @@ -201,215 +168,158 @@ | ||
| 201 | 168 | return \false; |
| 202 | 169 | } |
| 203 | 170 | return $this->uuid === $other->toString(); |
| 204 | 171 | } |
| 205 | - /** | |
| 206 | - * {@inheritDoc} | |
| 207 | - * | |
| 208 | - * @psalm-suppress MoreSpecificReturnType | |
| 209 | - * @psalm-suppress LessSpecificReturnStatement we know that {@see self::$uuid} is a non-empty string, so | |
| 210 | - * we know that {@see hex2bin} will retrieve a non-empty string too. | |
| 211 | - */ | |
| 212 | - public function getBytes(): string | |
| 172 | + public function getBytes() : string | |
| 213 | 173 | { |
| 214 | - /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */ | |
| 174 | + /** | |
| 175 | + * @var non-empty-string | |
| 176 | + * @phpstan-ignore possiblyImpure.functionCall, possiblyImpure.functionCall | |
| 177 | + */ | |
| 215 | 178 | return (string) hex2bin(str_replace('-', '', $this->uuid)); |
| 216 | 179 | } |
| 217 | - public function getFields(): FieldsInterface | |
| 180 | + public function getFields() : FieldsInterface | |
| 218 | 181 | { |
| 219 | 182 | return ($this->unwrapped ?? $this->unwrap())->getFields(); |
| 220 | 183 | } |
| 221 | - public function getHex(): Hexadecimal | |
| 184 | + public function getHex() : Hexadecimal | |
| 222 | 185 | { |
| 223 | 186 | return ($this->unwrapped ?? $this->unwrap())->getHex(); |
| 224 | 187 | } |
| 225 | - public function getInteger(): IntegerObject | |
| 188 | + public function getInteger() : IntegerObject | |
| 226 | 189 | { |
| 227 | 190 | return ($this->unwrapped ?? $this->unwrap())->getInteger(); |
| 228 | 191 | } |
| 229 | - public function toString(): string | |
| 192 | + public function toString() : string | |
| 230 | 193 | { |
| 231 | 194 | return $this->uuid; |
| 232 | 195 | } |
| 233 | - public function __toString(): string | |
| 196 | + public function __toString() : string | |
| 234 | 197 | { |
| 235 | 198 | return $this->uuid; |
| 236 | 199 | } |
| 237 | - public function jsonSerialize(): string | |
| 200 | + public function jsonSerialize() : string | |
| 238 | 201 | { |
| 239 | 202 | return $this->uuid; |
| 240 | 203 | } |
| 241 | 204 | /** |
| 242 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 243 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 244 | - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()} | |
| 245 | - * and use the arbitrary-precision math library of your choice to | |
| 246 | - * convert it to a string integer. | |
| 247 | - * | |
| 248 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 249 | - * @psalm-suppress DeprecatedMethod | |
| 250 | - * @psalm-suppress MixedArgument | |
| 251 | - * @psalm-suppress MixedMethodCall | |
| 205 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 206 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()} | |
| 207 | + * and use the arbitrary-precision math library of your choice to convert it to a string integer. | |
| 252 | 208 | */ |
| 253 | - public function getClockSeqHiAndReserved(): string | |
| 209 | + public function getClockSeqHiAndReserved() : string | |
| 254 | 210 | { |
| 255 | 211 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 256 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getClockSeqHiAndReserved()->toString()); | |
| 212 | + $fields = $instance->getFields(); | |
| 213 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 214 | + return $instance->getNumberConverter()->fromHex($fields->getClockSeqHiAndReserved()->toString()); | |
| 257 | 215 | } |
| 258 | 216 | /** |
| 259 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 260 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 261 | - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()} | |
| 262 | - * and use the arbitrary-precision math library of your choice to | |
| 263 | - * convert it to a string integer. | |
| 264 | - * | |
| 265 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 266 | - * @psalm-suppress DeprecatedMethod | |
| 267 | - * @psalm-suppress MixedArgument | |
| 268 | - * @psalm-suppress MixedMethodCall | |
| 217 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 218 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getClockSeqLow()} and use | |
| 219 | + * the arbitrary-precision math library of your choice to convert it to a string integer. | |
| 269 | 220 | */ |
| 270 | - public function getClockSeqLow(): string | |
| 221 | + public function getClockSeqLow() : string | |
| 271 | 222 | { |
| 272 | 223 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 273 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getClockSeqLow()->toString()); | |
| 224 | + $fields = $instance->getFields(); | |
| 225 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 226 | + return $instance->getNumberConverter()->fromHex($fields->getClockSeqLow()->toString()); | |
| 274 | 227 | } |
| 275 | 228 | /** |
| 276 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 277 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 278 | - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()} | |
| 279 | - * and use the arbitrary-precision math library of your choice to | |
| 280 | - * convert it to a string integer. | |
| 281 | - * | |
| 282 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 283 | - * @psalm-suppress DeprecatedMethod | |
| 284 | - * @psalm-suppress MixedArgument | |
| 285 | - * @psalm-suppress MixedMethodCall | |
| 229 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 230 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getClockSeq()} and use the | |
| 231 | + * arbitrary-precision math library of your choice to convert it to a string integer. | |
| 286 | 232 | */ |
| 287 | - public function getClockSequence(): string | |
| 233 | + public function getClockSequence() : string | |
| 288 | 234 | { |
| 289 | 235 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 290 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getClockSeq()->toString()); | |
| 236 | + $fields = $instance->getFields(); | |
| 237 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 238 | + return $instance->getNumberConverter()->fromHex($fields->getClockSeq()->toString()); | |
| 291 | 239 | } |
| 292 | 240 | /** |
| 293 | - * @deprecated This method will be removed in 5.0.0. There is no direct | |
| 294 | - * alternative, but the same information may be obtained by splitting | |
| 295 | - * in half the value returned by {@see UuidInterface::getHex()}. | |
| 296 | - * | |
| 297 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 298 | - * @psalm-suppress DeprecatedMethod | |
| 299 | - * @psalm-suppress MixedArgument | |
| 300 | - * @psalm-suppress MixedMethodCall | |
| 241 | + * @deprecated This method will be removed in 5.0.0. There is no direct alternative, but the same information may be | |
| 242 | + * obtained by splitting in half the value returned by {@see UuidInterface::getHex()}. | |
| 301 | 243 | */ |
| 302 | - public function getLeastSignificantBits(): string | |
| 244 | + public function getLeastSignificantBits() : string | |
| 303 | 245 | { |
| 304 | 246 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 305 | 247 | return $instance->getNumberConverter()->fromHex(substr($instance->getHex()->toString(), 16)); |
| 306 | 248 | } |
| 307 | 249 | /** |
| 308 | - * @deprecated This method will be removed in 5.0.0. There is no direct | |
| 309 | - * alternative, but the same information may be obtained by splitting | |
| 310 | - * in half the value returned by {@see UuidInterface::getHex()}. | |
| 311 | - * | |
| 312 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 313 | - * @psalm-suppress DeprecatedMethod | |
| 314 | - * @psalm-suppress MixedArgument | |
| 315 | - * @psalm-suppress MixedMethodCall | |
| 250 | + * @deprecated This method will be removed in 5.0.0. There is no direct alternative, but the same information may be | |
| 251 | + * obtained by splitting in half the value returned by {@see UuidInterface::getHex()}. | |
| 316 | 252 | */ |
| 317 | - public function getMostSignificantBits(): string | |
| 253 | + public function getMostSignificantBits() : string | |
| 318 | 254 | { |
| 319 | 255 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 320 | 256 | return $instance->getNumberConverter()->fromHex(substr($instance->getHex()->toString(), 0, 16)); |
| 321 | 257 | } |
| 322 | 258 | /** |
| 323 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 324 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 325 | - * instance, you may call {@see Rfc4122FieldsInterface::getNode()} | |
| 326 | - * and use the arbitrary-precision math library of your choice to | |
| 327 | - * convert it to a string integer. | |
| 328 | - * | |
| 329 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 330 | - * @psalm-suppress DeprecatedMethod | |
| 331 | - * @psalm-suppress MixedArgument | |
| 332 | - * @psalm-suppress MixedMethodCall | |
| 259 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 260 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getNode()} and use the | |
| 261 | + * arbitrary-precision math library of your choice to convert it to a string integer. | |
| 333 | 262 | */ |
| 334 | - public function getNode(): string | |
| 263 | + public function getNode() : string | |
| 335 | 264 | { |
| 336 | 265 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 337 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getNode()->toString()); | |
| 266 | + $fields = $instance->getFields(); | |
| 267 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 268 | + return $instance->getNumberConverter()->fromHex($fields->getNode()->toString()); | |
| 338 | 269 | } |
| 339 | 270 | /** |
| 340 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 341 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 342 | - * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()} | |
| 343 | - * and use the arbitrary-precision math library of your choice to | |
| 344 | - * convert it to a string integer. | |
| 345 | - * | |
| 346 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 347 | - * @psalm-suppress DeprecatedMethod | |
| 348 | - * @psalm-suppress MixedArgument | |
| 349 | - * @psalm-suppress MixedMethodCall | |
| 271 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 272 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()} and | |
| 273 | + * use the arbitrary-precision math library of your choice to convert it to a string integer. | |
| 350 | 274 | */ |
| 351 | - public function getTimeHiAndVersion(): string | |
| 275 | + public function getTimeHiAndVersion() : string | |
| 352 | 276 | { |
| 353 | 277 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 354 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getTimeHiAndVersion()->toString()); | |
| 278 | + $fields = $instance->getFields(); | |
| 279 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 280 | + return $instance->getNumberConverter()->fromHex($fields->getTimeHiAndVersion()->toString()); | |
| 355 | 281 | } |
| 356 | 282 | /** |
| 357 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 358 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 359 | - * instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()} | |
| 360 | - * and use the arbitrary-precision math library of your choice to | |
| 361 | - * convert it to a string integer. | |
| 362 | - * | |
| 363 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 364 | - * @psalm-suppress DeprecatedMethod | |
| 365 | - * @psalm-suppress MixedArgument | |
| 366 | - * @psalm-suppress MixedMethodCall | |
| 283 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 284 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getTimeLow()} and use the | |
| 285 | + * arbitrary-precision math library of your choice to convert it to a string integer. | |
| 367 | 286 | */ |
| 368 | - public function getTimeLow(): string | |
| 287 | + public function getTimeLow() : string | |
| 369 | 288 | { |
| 370 | 289 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 371 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getTimeLow()->toString()); | |
| 290 | + $fields = $instance->getFields(); | |
| 291 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 292 | + return $instance->getNumberConverter()->fromHex($fields->getTimeLow()->toString()); | |
| 372 | 293 | } |
| 373 | 294 | /** |
| 374 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 375 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 376 | - * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()} | |
| 377 | - * and use the arbitrary-precision math library of your choice to | |
| 378 | - * convert it to a string integer. | |
| 379 | - * | |
| 380 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 381 | - * @psalm-suppress DeprecatedMethod | |
| 382 | - * @psalm-suppress MixedArgument | |
| 383 | - * @psalm-suppress MixedMethodCall | |
| 295 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 296 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()} and use the | |
| 297 | + * arbitrary-precision math library of your choice to convert it to a string integer. | |
| 384 | 298 | */ |
| 385 | - public function getTimeMid(): string | |
| 299 | + public function getTimeMid() : string | |
| 386 | 300 | { |
| 387 | 301 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 388 | - return $instance->getNumberConverter()->fromHex($instance->getFields()->getTimeMid()->toString()); | |
| 302 | + $fields = $instance->getFields(); | |
| 303 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 304 | + return $instance->getNumberConverter()->fromHex($fields->getTimeMid()->toString()); | |
| 389 | 305 | } |
| 390 | 306 | /** |
| 391 | - * @deprecated Use {@see UuidInterface::getFields()} to get a | |
| 392 | - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} | |
| 393 | - * instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()} | |
| 394 | - * and use the arbitrary-precision math library of your choice to | |
| 395 | - * convert it to a string integer. | |
| 396 | - * | |
| 397 | - * @psalm-suppress UndefinedInterfaceMethod | |
| 398 | - * @psalm-suppress DeprecatedMethod | |
| 399 | - * @psalm-suppress MixedArgument | |
| 400 | - * @psalm-suppress MixedMethodCall | |
| 307 | + * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a | |
| 308 | + * {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()} and use | |
| 309 | + * the arbitrary-precision math library of your choice to convert it to a string integer. | |
| 401 | 310 | */ |
| 402 | - public function getTimestamp(): string | |
| 311 | + public function getTimestamp() : string | |
| 403 | 312 | { |
| 404 | 313 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 405 | 314 | $fields = $instance->getFields(); |
| 315 | + assert($fields instanceof \Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Rfc4122\FieldsInterface); | |
| 406 | 316 | if ($fields->getVersion() !== 1) { |
| 407 | 317 | throw new UnsupportedOperationException('Not a time-based UUID'); |
| 408 | 318 | } |
| 409 | 319 | return $instance->getNumberConverter()->fromHex($fields->getTimestamp()->toString()); |
| 410 | 320 | } |
| 411 | - public function toUuidV1(): UuidV1 | |
| 321 | + public function toUuidV1() : UuidV1 | |
| 412 | 322 | { |
| 413 | 323 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 414 | 324 | if ($instance instanceof UuidV1) { |
| 415 | 325 | return $instance; |
| @@ -416,24 +326,15 @@ | ||
| 416 | 326 | } |
| 417 | 327 | assert($instance instanceof UuidV6); |
| 418 | 328 | return $instance->toUuidV1(); |
| 419 | 329 | } |
| 420 | - public function toUuidV6(): UuidV6 | |
| 330 | + public function toUuidV6() : UuidV6 | |
| 421 | 331 | { |
| 422 | 332 | $instance = $this->unwrapped ?? $this->unwrap(); |
| 423 | 333 | assert($instance instanceof UuidV6); |
| 424 | 334 | return $instance; |
| 425 | 335 | } |
| 426 | - /** | |
| 427 | - * @psalm-suppress ImpureMethodCall the retrieval of the factory is a clear violation of purity here: this is a | |
| 428 | - * known pitfall of the design of this library, where a value object contains | |
| 429 | - * a mutable reference to a factory. We use a fixed factory here, so the violation | |
| 430 | - * will not have real-world effects, as this object is only instantiated with the | |
| 431 | - * default factory settings/features. | |
| 432 | - * @psalm-suppress InaccessibleProperty property {@see $unwrapped} is used as a cache: we don't expose it to the | |
| 433 | - * outside world, so we should be fine here. | |
| 434 | - */ | |
| 435 | - private function unwrap(): UuidInterface | |
| 336 | + private function unwrap() : UuidInterface | |
| 436 | 337 | { |
| 437 | 338 | return $this->unwrapped = (new UuidFactory())->fromString($this->uuid); |
| 438 | 339 | } |
| 439 | 340 | } |