mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
chore(deps-dev): upgrade PHPStan
This commit is contained in:
@@ -70,6 +70,7 @@ class BuilderCollection extends AbstractCollection
|
||||
$this->data = array_filter(
|
||||
$data,
|
||||
function ($unserialized): bool {
|
||||
/** @phpstan-ignore instanceof.alwaysTrue */
|
||||
return $unserialized instanceof UuidBuilderInterface;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -64,7 +64,6 @@ class OrderedTimeCodec extends StringCodec
|
||||
|
||||
$bytes = $uuid->getFields()->getBytes();
|
||||
|
||||
/** @var non-empty-string */
|
||||
return $bytes[6] . $bytes[7]
|
||||
. $bytes[4] . $bytes[5]
|
||||
. $bytes[0] . $bytes[1] . $bytes[2] . $bytes[3]
|
||||
|
||||
@@ -92,6 +92,7 @@ class PhpTimeConverter implements TimeConverterInterface
|
||||
|
||||
// Check to see whether we've overflowed the max/min integer size.
|
||||
// If so, we will default to a different time converter.
|
||||
// @phpstan-ignore function.alreadyNarrowedType (the integer value might have overflowed)
|
||||
if (!is_int($uuidTime)) {
|
||||
return $this->fallbackConverter->calculateTime(
|
||||
$seconds->toString(),
|
||||
|
||||
@@ -85,6 +85,8 @@ class FeatureSet
|
||||
* system node ID (primarily for testing purposes)
|
||||
* @param bool $enablePecl True to enable the use of the PeclUuidTimeGenerator
|
||||
* to generate version 1 UUIDs
|
||||
*
|
||||
* @phpstan-ignore constructor.unusedParameter ($forceNoBigNumber is deprecated)
|
||||
*/
|
||||
public function __construct(
|
||||
bool $useGuids = false,
|
||||
|
||||
@@ -82,6 +82,8 @@ class CombGenerator implements RandomGeneratorInterface
|
||||
}
|
||||
|
||||
$hash = '';
|
||||
|
||||
/** @phpstan-ignore greater.alwaysTrue (TIMESTAMP_BYTES constant could change in child classes) */
|
||||
if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) {
|
||||
$hash = $this->generator->generate($length - self::TIMESTAMP_BYTES);
|
||||
}
|
||||
|
||||
@@ -29,19 +29,12 @@ class DefaultNameGenerator implements NameGeneratorInterface
|
||||
public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string
|
||||
{
|
||||
try {
|
||||
/** @var string|bool $bytes */
|
||||
$bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true);
|
||||
return hash($hashAlgorithm, $ns->getBytes() . $name, true);
|
||||
} catch (ValueError $e) {
|
||||
$bytes = false; // keep same behavior than PHP 7
|
||||
throw new NameException(
|
||||
message: sprintf('Unable to hash namespace and name with algorithm \'%s\'', $hashAlgorithm),
|
||||
previous: $e,
|
||||
);
|
||||
}
|
||||
|
||||
if ($bytes === false) {
|
||||
throw new NameException(sprintf(
|
||||
'Unable to hash namespace and name with algorithm \'%s\'',
|
||||
$hashAlgorithm
|
||||
));
|
||||
}
|
||||
|
||||
return (string) $bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,6 @@ class PeclUuidNameGenerator implements NameGeneratorInterface
|
||||
),
|
||||
};
|
||||
|
||||
return uuid_parse($uuid);
|
||||
return (string) uuid_parse($uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,6 @@ class PeclUuidRandomGenerator implements RandomGeneratorInterface
|
||||
{
|
||||
$uuid = uuid_create(UUID_TYPE_RANDOM);
|
||||
|
||||
return uuid_parse($uuid);
|
||||
return (string) uuid_parse($uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,6 @@ class PeclUuidTimeGenerator implements TimeGeneratorInterface
|
||||
{
|
||||
$uuid = uuid_create(UUID_TYPE_TIME);
|
||||
|
||||
return uuid_parse($uuid);
|
||||
return (string) uuid_parse($uuid);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -37,7 +37,7 @@ use function unpack;
|
||||
use const STR_PAD_LEFT;
|
||||
|
||||
/**
|
||||
* GUIDs are comprised of a set of named fields, according to RFC 4122
|
||||
* GUIDs consist of a set of named fields, according to RFC 4122
|
||||
*
|
||||
* @see Guid
|
||||
*
|
||||
@@ -89,7 +89,7 @@ final class Fields implements FieldsInterface
|
||||
public function getTimeLow(): Hexadecimal
|
||||
{
|
||||
// Swap the bytes from little endian to network byte order.
|
||||
/** @var array $hex */
|
||||
/** @var string[] $hex */
|
||||
$hex = unpack(
|
||||
'H*',
|
||||
pack(
|
||||
@@ -99,13 +99,13 @@ final class Fields implements FieldsInterface
|
||||
)
|
||||
);
|
||||
|
||||
return new Hexadecimal((string) ($hex[1] ?? ''));
|
||||
return new Hexadecimal($hex[1] ?? '');
|
||||
}
|
||||
|
||||
public function getTimeMid(): Hexadecimal
|
||||
{
|
||||
// Swap the bytes from little endian to network byte order.
|
||||
/** @var array $hex */
|
||||
/** @var string[] $hex */
|
||||
$hex = unpack(
|
||||
'H*',
|
||||
pack(
|
||||
@@ -114,13 +114,13 @@ final class Fields implements FieldsInterface
|
||||
)
|
||||
);
|
||||
|
||||
return new Hexadecimal((string) ($hex[1] ?? ''));
|
||||
return new Hexadecimal($hex[1] ?? '');
|
||||
}
|
||||
|
||||
public function getTimeHiAndVersion(): Hexadecimal
|
||||
{
|
||||
// Swap the bytes from little endian to network byte order.
|
||||
/** @var array $hex */
|
||||
/** @var string[] $hex */
|
||||
$hex = unpack(
|
||||
'H*',
|
||||
pack(
|
||||
@@ -129,7 +129,7 @@ final class Fields implements FieldsInterface
|
||||
)
|
||||
);
|
||||
|
||||
return new Hexadecimal((string) ($hex[1] ?? ''));
|
||||
return new Hexadecimal($hex[1] ?? '');
|
||||
}
|
||||
|
||||
public function getTimestamp(): Hexadecimal
|
||||
@@ -176,10 +176,10 @@ final class Fields implements FieldsInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var array $parts */
|
||||
/** @var int[] $parts */
|
||||
$parts = unpack('n*', $this->bytes);
|
||||
|
||||
return ((int) $parts[4] >> 4) & 0x00f;
|
||||
return ($parts[4] >> 4) & 0x00f;
|
||||
}
|
||||
|
||||
private function isCorrectVariant(): bool
|
||||
|
||||
@@ -38,11 +38,9 @@ use function substr;
|
||||
* conversion. This object optimizes instantiation, serialization and string conversion time, at the cost of
|
||||
* increased overhead for more advanced UUID operations.
|
||||
*
|
||||
* @internal this type is used internally for performance reasons, and is not supposed to be directly referenced
|
||||
* @internal this type is used internally for performance reasons and is not supposed to be directly referenced
|
||||
* in consumer libraries.
|
||||
*
|
||||
* @immutable
|
||||
*
|
||||
* Note: the {@see FieldsInterface} does not declare methods that deprecated API
|
||||
* relies upon: the API has been ported from the {@see \Ramsey\Uuid\Uuid} definition,
|
||||
* and is deprecated anyway.
|
||||
|
||||
@@ -199,9 +199,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
/** @var string[] $userGroups */
|
||||
$userGroups = preg_split('/\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$firstGroup = trim($userGroups[1] ?? '', "* \t\n\r\0\x0B");
|
||||
|
||||
if ($firstGroup === '') {
|
||||
@@ -214,9 +212,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
/** @var string[] $userGroup */
|
||||
$userGroup = preg_split('/\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$sid = $userGroup[1] ?? '';
|
||||
|
||||
if (($lastHyphen = strrpos($sid, '-')) === false) {
|
||||
|
||||
@@ -56,6 +56,7 @@ class NodeProviderCollection extends AbstractCollection
|
||||
$this->data = array_filter(
|
||||
$data,
|
||||
function ($unserialized): bool {
|
||||
/** @phpstan-ignore-next-line */
|
||||
return $unserialized instanceof NodeProviderInterface;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -72,10 +72,11 @@ class SystemNodeProvider implements NodeProviderInterface
|
||||
*/
|
||||
protected function getNodeFromSystem(): string
|
||||
{
|
||||
/** @var string | null $node */
|
||||
static $node = null;
|
||||
|
||||
if ($node !== null) {
|
||||
return (string) $node;
|
||||
return $node;
|
||||
}
|
||||
|
||||
// First, try a Linux-specific approach.
|
||||
@@ -173,9 +174,10 @@ class SystemNodeProvider implements NodeProviderInterface
|
||||
$macs = array_map($trim, $macs);
|
||||
|
||||
// Remove invalid entries.
|
||||
$macs = array_filter($macs, function (string $address) {
|
||||
return $address !== '00:00:00:00:00:00'
|
||||
&& preg_match(self::SYSFS_PATTERN, $address);
|
||||
$macs = array_filter($macs, function (mixed $address): bool {
|
||||
assert(is_string($address));
|
||||
|
||||
return $address !== '00:00:00:00:00:00' && preg_match(self::SYSFS_PATTERN, $address);
|
||||
});
|
||||
|
||||
/** @var string|bool $mac */
|
||||
|
||||
@@ -36,7 +36,7 @@ use function str_starts_with;
|
||||
final class Decimal implements NumberInterface
|
||||
{
|
||||
private string $value;
|
||||
private bool $isNegative = false;
|
||||
private bool $isNegative;
|
||||
|
||||
public function __construct(float | int | string | self $value)
|
||||
{
|
||||
@@ -61,6 +61,8 @@ final class Decimal implements NumberInterface
|
||||
|
||||
if (str_starts_with($value, '-')) {
|
||||
$this->isNegative = true;
|
||||
} else {
|
||||
$this->isNegative = false;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
|
||||
@@ -42,6 +42,9 @@ final class Integer implements NumberInterface
|
||||
*/
|
||||
private string $value;
|
||||
|
||||
/**
|
||||
* @phpstan-ignore property.readOnlyByPhpDocDefaultValue
|
||||
*/
|
||||
private bool $isNegative = false;
|
||||
|
||||
public function __construct(float | int | string | self $value)
|
||||
@@ -145,6 +148,7 @@ final class Integer implements NumberInterface
|
||||
if ($sign === '-' && $value !== '0') {
|
||||
$value = $sign . $value;
|
||||
|
||||
/** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */
|
||||
$this->isNegative = true;
|
||||
}
|
||||
|
||||
|
||||
+17
-1
@@ -223,12 +223,16 @@ class Uuid implements UuidInterface
|
||||
self::DCE_DOMAIN_ORG => 'org',
|
||||
];
|
||||
|
||||
/**
|
||||
* @phpstan-ignore property.readOnlyByPhpDocDefaultValue
|
||||
*/
|
||||
private static ?UuidFactoryInterface $factory = null;
|
||||
|
||||
/**
|
||||
* @var bool flag to detect if the UUID factory was replaced internally,
|
||||
* which disables all optimizations for the default/happy path internal
|
||||
* scenarios
|
||||
* @phpstan-ignore property.readOnlyByPhpDocDefaultValue
|
||||
*/
|
||||
private static bool $factoryReplaced = false;
|
||||
|
||||
@@ -321,9 +325,16 @@ class Uuid implements UuidInterface
|
||||
$uuid = self::getFactory()->fromString($data);
|
||||
}
|
||||
|
||||
/** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */
|
||||
$this->codec = $uuid->codec;
|
||||
|
||||
/** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */
|
||||
$this->numberConverter = $uuid->numberConverter;
|
||||
|
||||
/** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */
|
||||
$this->fields = $uuid->fields;
|
||||
|
||||
/** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */
|
||||
$this->timeConverter = $uuid->timeConverter;
|
||||
}
|
||||
|
||||
@@ -519,7 +530,10 @@ class Uuid implements UuidInterface
|
||||
$factory = self::getFactory();
|
||||
|
||||
if (method_exists($factory, 'fromHexadecimal')) {
|
||||
return $factory->fromHexadecimal($hex);
|
||||
$uuid = $factory->fromHexadecimal($hex);
|
||||
assert($uuid instanceof UuidInterface);
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
throw new BadMethodCallException('The method fromHexadecimal() does not exist on the provided factory');
|
||||
@@ -546,6 +560,8 @@ class Uuid implements UuidInterface
|
||||
* @param string $uuid A string to validate as a UUID
|
||||
*
|
||||
* @return bool True if the string is a valid UUID, false otherwise
|
||||
*
|
||||
* @phpstan-assert-if-true =non-empty-string $uuid
|
||||
*/
|
||||
public static function isValid(string $uuid): bool
|
||||
{
|
||||
|
||||
+4
-4
@@ -466,14 +466,14 @@ class UuidFactory implements UuidFactoryInterface
|
||||
*/
|
||||
private function uuidFromBytesAndVersion(string $bytes, int $version): UuidInterface
|
||||
{
|
||||
/** @var array $unpackedTime */
|
||||
/** @var int[] $unpackedTime */
|
||||
$unpackedTime = unpack('n*', substr($bytes, 6, 2));
|
||||
$timeHi = (int) $unpackedTime[1];
|
||||
$timeHi = $unpackedTime[1];
|
||||
$timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, $version));
|
||||
|
||||
/** @var array $unpackedClockSeq */
|
||||
/** @var int[] $unpackedClockSeq */
|
||||
$unpackedClockSeq = unpack('n*', substr($bytes, 8, 2));
|
||||
$clockSeqHi = (int) $unpackedClockSeq[1];
|
||||
$clockSeqHi = $unpackedClockSeq[1];
|
||||
$clockSeqHiAndReserved = pack('n*', BinaryUtils::applyVariant($clockSeqHi));
|
||||
|
||||
$bytes = substr_replace($bytes, $timeHiAndVersion, 6, 2);
|
||||
|
||||
Reference in New Issue
Block a user