处理 vendor 依赖错误问题

This commit is contained in:
柳清爽
2025-03-25 18:31:48 +08:00
parent f7f48a03fe
commit 4af129acf8
416 changed files with 26268 additions and 28381 deletions

View File

@@ -17,9 +17,8 @@ namespace MyCLabs\Enum;
*
* @psalm-template T
* @psalm-immutable
* @psalm-consistent-constructor
*/
abstract class Enum implements \JsonSerializable, \Stringable
abstract class Enum implements \JsonSerializable
{
/**
* Enum value
@@ -29,13 +28,6 @@ abstract class Enum implements \JsonSerializable, \Stringable
*/
protected $value;
/**
* Enum key, the constant name
*
* @var string
*/
private $key;
/**
* Store existing constants in a static cache per object.
*
@@ -59,7 +51,7 @@ abstract class Enum implements \JsonSerializable, \Stringable
* @psalm-pure
* @param mixed $value
*
* @psalm-param T $value
* @psalm-param static<T>|T $value
* @throws \UnexpectedValueException if incompatible type is given.
*/
public function __construct($value)
@@ -69,40 +61,15 @@ abstract class Enum implements \JsonSerializable, \Stringable
$value = $value->getValue();
}
/** @psalm-suppress ImplicitToStringCast assertValidValueReturningKey returns always a string but psalm has currently an issue here */
$this->key = static::assertValidValueReturningKey($value);
if (!$this->isValid($value)) {
/** @psalm-suppress InvalidCast */
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);
}
/** @psalm-var T */
$this->value = $value;
}
/**
* This method exists only for the compatibility reason when deserializing a previously serialized version
* that didn't had the key property
*/
public function __wakeup()
{
/** @psalm-suppress DocblockTypeContradiction key can be null when deserializing an enum without the key */
if ($this->key === null) {
/**
* @psalm-suppress InaccessibleProperty key is not readonly as marked by psalm
* @psalm-suppress PossiblyFalsePropertyAssignmentValue deserializing a case that was removed
*/
$this->key = static::search($this->value);
}
}
/**
* @param mixed $value
* @return static
*/
public static function from($value): self
{
$key = static::assertValidValueReturningKey($value);
return self::__callStatic($key, []);
}
/**
* @psalm-pure
* @return mixed
@@ -117,11 +84,11 @@ abstract class Enum implements \JsonSerializable, \Stringable
* Returns the enum key (i.e. the constant name).
*
* @psalm-pure
* @return string
* @return mixed
*/
public function getKey()
{
return $this->key;
return static::search($this->value);
}
/**
@@ -196,9 +163,7 @@ abstract class Enum implements \JsonSerializable, \Stringable
$class = static::class;
if (!isset(static::$cache[$class])) {
/** @psalm-suppress ImpureMethodCall this reflection API usage has no side-effects here */
$reflection = new \ReflectionClass($class);
/** @psalm-suppress ImpureMethodCall this reflection API usage has no side-effects here */
static::$cache[$class] = $reflection->getConstants();
}
@@ -211,7 +176,6 @@ abstract class Enum implements \JsonSerializable, \Stringable
* @param $value
* @psalm-param mixed $value
* @psalm-pure
* @psalm-assert-if-true T $value
* @return bool
*/
public static function isValid($value)
@@ -219,35 +183,6 @@ abstract class Enum implements \JsonSerializable, \Stringable
return \in_array($value, static::toArray(), true);
}
/**
* Asserts valid enum value
*
* @psalm-pure
* @psalm-assert T $value
* @param mixed $value
*/
public static function assertValidValue($value): void
{
self::assertValidValueReturningKey($value);
}
/**
* Asserts valid enum value
*
* @psalm-pure
* @psalm-assert T $value
* @param mixed $value
* @return string
*/
private static function assertValidValueReturningKey($value): string
{
if (false === ($key = static::search($value))) {
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);
}
return $key;
}
/**
* Check if is valid enum key
*
@@ -266,11 +201,11 @@ abstract class Enum implements \JsonSerializable, \Stringable
/**
* Return key for value
*
* @param mixed $value
* @param $value
*
* @psalm-param mixed $value
* @psalm-pure
* @return string|false
* @return mixed
*/
public static function search($value)
{
@@ -285,8 +220,6 @@ abstract class Enum implements \JsonSerializable, \Stringable
*
* @return static
* @throws \BadMethodCallException
*
* @psalm-pure
*/
public static function __callStatic($name, $arguments)
{
@@ -310,7 +243,6 @@ abstract class Enum implements \JsonSerializable, \Stringable
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @psalm-pure
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->getValue();