mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 14:08:46 +02:00
N°5809 Update laminas/laminas-mail from 2.16.0 to 2.22.0
This commit is contained in:
@@ -7,6 +7,7 @@ namespace Laminas\Stdlib;
|
||||
use Traversable;
|
||||
|
||||
use function array_shift;
|
||||
use function get_object_vars;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function method_exists;
|
||||
@@ -16,6 +17,10 @@ use function str_replace;
|
||||
use function strtolower;
|
||||
use function ucwords;
|
||||
|
||||
/**
|
||||
* @template TValue
|
||||
* @implements ParameterObjectInterface<string, TValue>
|
||||
*/
|
||||
abstract class AbstractOptions implements ParameterObjectInterface
|
||||
{
|
||||
// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore,WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCapsProperty
|
||||
@@ -33,7 +38,7 @@ abstract class AbstractOptions implements ParameterObjectInterface
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Traversable|null $options
|
||||
* @param iterable<string, TValue>|AbstractOptions<TValue>|null $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
@@ -45,7 +50,7 @@ abstract class AbstractOptions implements ParameterObjectInterface
|
||||
/**
|
||||
* Set one or more configuration properties
|
||||
*
|
||||
* @param array|Traversable|AbstractOptions $options
|
||||
* @param iterable<string, TValue>|AbstractOptions<TValue> $options
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return AbstractOptions Provides fluent interface
|
||||
*/
|
||||
@@ -77,19 +82,20 @@ abstract class AbstractOptions implements ParameterObjectInterface
|
||||
/**
|
||||
* Cast to array
|
||||
*
|
||||
* @return array
|
||||
* @return array<string, TValue>
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$array = [];
|
||||
|
||||
/** @param string[] $letters */
|
||||
$transform = static function (array $letters): string {
|
||||
/** @var list<string> $letters */
|
||||
$letter = array_shift($letters);
|
||||
return '_' . strtolower($letter);
|
||||
};
|
||||
|
||||
foreach ($this as $key => $value) {
|
||||
/** @psalm-var TValue $value */
|
||||
foreach (get_object_vars($this) as $key => $value) {
|
||||
if ($key === '__strictMode__') {
|
||||
continue;
|
||||
}
|
||||
@@ -106,7 +112,7 @@ abstract class AbstractOptions implements ParameterObjectInterface
|
||||
* @see ParameterObject::__set()
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param TValue|null $value
|
||||
* @throws Exception\BadMethodCallException
|
||||
* @return void
|
||||
*/
|
||||
@@ -137,7 +143,7 @@ abstract class AbstractOptions implements ParameterObjectInterface
|
||||
*
|
||||
* @param string $key
|
||||
* @throws Exception\BadMethodCallException
|
||||
* @return mixed
|
||||
* @return TValue
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Laminas\Stdlib;
|
||||
|
||||
use AllowDynamicProperties;
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
use IteratorAggregate;
|
||||
@@ -17,7 +19,7 @@ use function array_keys;
|
||||
use function asort;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function get_debug_type;
|
||||
use function get_object_vars;
|
||||
use function gettype;
|
||||
use function in_array;
|
||||
@@ -30,7 +32,7 @@ use function natcasesort;
|
||||
use function natsort;
|
||||
use function serialize;
|
||||
use function sprintf;
|
||||
use function strpos;
|
||||
use function str_starts_with;
|
||||
use function uasort;
|
||||
use function uksort;
|
||||
use function unserialize;
|
||||
@@ -39,7 +41,13 @@ use function unserialize;
|
||||
* Custom framework ArrayObject implementation
|
||||
*
|
||||
* Extends version-specific "abstract" implementation.
|
||||
*
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
* @template-implements IteratorAggregate<TKey, TValue>
|
||||
* @template-implements ArrayAccess<TKey, TValue>
|
||||
*/
|
||||
#[AllowDynamicProperties]
|
||||
class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Countable
|
||||
{
|
||||
/**
|
||||
@@ -53,26 +61,24 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
*/
|
||||
public const ARRAY_AS_PROPS = 2;
|
||||
|
||||
/** @var array */
|
||||
/** @var array<TKey, TValue> */
|
||||
protected $storage;
|
||||
|
||||
/** @var int */
|
||||
/** @var self::STD_PROP_LIST|self::ARRAY_AS_PROPS */
|
||||
protected $flag;
|
||||
|
||||
/** @var string */
|
||||
/** @var class-string<Iterator> */
|
||||
protected $iteratorClass;
|
||||
|
||||
/** @var array */
|
||||
/** @var list<string> */
|
||||
protected $protectedProperties;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|object $input Object values must act like ArrayAccess
|
||||
* @param int $flags
|
||||
* @param string $iteratorClass
|
||||
* @param array<TKey, TValue>|object $input Object values must act like ArrayAccess
|
||||
* @param self::STD_PROP_LIST|self::ARRAY_AS_PROPS $flags
|
||||
* @param class-string<Iterator> $iteratorClass
|
||||
*/
|
||||
public function __construct($input = [], $flags = self::STD_PROP_LIST, $iteratorClass = 'ArrayIterator')
|
||||
public function __construct($input = [], $flags = self::STD_PROP_LIST, $iteratorClass = ArrayIterator::class)
|
||||
{
|
||||
$this->setFlags($flags);
|
||||
$this->storage = $input;
|
||||
@@ -83,10 +89,10 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Returns whether the requested key exists
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param TKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($key)
|
||||
public function __isset(mixed $key)
|
||||
{
|
||||
if ($this->flag === self::ARRAY_AS_PROPS) {
|
||||
return $this->offsetExists($key);
|
||||
@@ -102,11 +108,11 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Sets the value at the specified key to value
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @param TKey $key
|
||||
* @param TValue $value
|
||||
* @return void
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
public function __set(mixed $key, mixed $value)
|
||||
{
|
||||
if ($this->flag === self::ARRAY_AS_PROPS) {
|
||||
$this->offsetSet($key, $value);
|
||||
@@ -123,10 +129,10 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Unsets the value at the specified key
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param TKey $key
|
||||
* @return void
|
||||
*/
|
||||
public function __unset($key)
|
||||
public function __unset(mixed $key)
|
||||
{
|
||||
if ($this->flag === self::ARRAY_AS_PROPS) {
|
||||
$this->offsetUnset($key);
|
||||
@@ -143,10 +149,10 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Returns the value at the specified key by reference
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
* @param TKey $key
|
||||
* @return TValue|null
|
||||
*/
|
||||
public function &__get($key)
|
||||
public function &__get(mixed $key)
|
||||
{
|
||||
if ($this->flag === self::ARRAY_AS_PROPS) {
|
||||
$ret = &$this->offsetGet($key);
|
||||
@@ -164,10 +170,10 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Appends the value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param TValue $value
|
||||
* @return void
|
||||
*/
|
||||
public function append($value)
|
||||
public function append(mixed $value)
|
||||
{
|
||||
$this->storage[] = $value;
|
||||
}
|
||||
@@ -185,7 +191,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Get the number of public properties in the ArrayObject
|
||||
*
|
||||
* @return int
|
||||
* @return positive-int|0
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function count()
|
||||
@@ -196,8 +202,8 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Exchange the array for another one.
|
||||
*
|
||||
* @param array|ArrayObject|ArrayIterator|object $data
|
||||
* @return array
|
||||
* @param array<TKey, TValue>|ArrayObject<TKey, TValue>|ArrayIterator<TKey, TValue>|object $data
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public function exchangeArray($data)
|
||||
{
|
||||
@@ -224,7 +230,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Creates a copy of the ArrayObject.
|
||||
*
|
||||
* @return array
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public function getArrayCopy()
|
||||
{
|
||||
@@ -234,7 +240,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Gets the behavior flags.
|
||||
*
|
||||
* @return int
|
||||
* @return self::STD_PROP_LIST|self::ARRAY_AS_PROPS
|
||||
*/
|
||||
public function getFlags()
|
||||
{
|
||||
@@ -244,7 +250,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Create a new iterator from an ArrayObject instance
|
||||
*
|
||||
* @return Iterator
|
||||
* @return Iterator<TKey, TValue>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
@@ -257,7 +263,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Gets the iterator classname for the ArrayObject.
|
||||
*
|
||||
* @return string
|
||||
* @return class-string<Iterator>
|
||||
*/
|
||||
public function getIteratorClass()
|
||||
{
|
||||
@@ -297,23 +303,23 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Returns whether the requested key exists
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param TKey $key
|
||||
* @return bool
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($key)
|
||||
public function offsetExists(mixed $key)
|
||||
{
|
||||
return isset($this->storage[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value at the specified key
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
* @param TKey $key
|
||||
* @return TValue|null
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function &offsetGet($key)
|
||||
public function &offsetGet(mixed $key)
|
||||
{
|
||||
$ret = null;
|
||||
if (! $this->offsetExists($key)) {
|
||||
@@ -327,27 +333,27 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Sets the value at the specified key to value
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @param TKey $offset
|
||||
* @param TValue $value
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($key, $value)
|
||||
public function offsetSet(mixed $offset, mixed $value)
|
||||
{
|
||||
$this->storage[$key] = $value;
|
||||
$this->storage[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets the value at the specified key
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param TKey $offset
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($key)
|
||||
public function offsetUnset(mixed $offset)
|
||||
{
|
||||
if ($this->offsetExists($key)) {
|
||||
unset($this->storage[$key]);
|
||||
if ($this->offsetExists($offset)) {
|
||||
unset($this->storage[$offset]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,7 +370,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Magic method used for serializing of an instance.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function __serialize()
|
||||
{
|
||||
@@ -374,7 +380,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Sets the behavior flags
|
||||
*
|
||||
* @param int $flags
|
||||
* @param self::STD_PROP_LIST|self::ARRAY_AS_PROPS $flags
|
||||
* @return void
|
||||
*/
|
||||
public function setFlags($flags)
|
||||
@@ -385,7 +391,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Sets the iterator classname for the ArrayObject
|
||||
*
|
||||
* @param string $class
|
||||
* @param class-string<Iterator> $class
|
||||
* @return void
|
||||
*/
|
||||
public function setIteratorClass($class)
|
||||
@@ -396,7 +402,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($class, '\\') === 0) {
|
||||
if (str_starts_with($class, '\\')) {
|
||||
$class = '\\' . $class;
|
||||
if (class_exists($class)) {
|
||||
$this->iteratorClass = $class;
|
||||
@@ -411,7 +417,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Sort the entries with a user-defined comparison function and maintain key association
|
||||
*
|
||||
* @param callable $function
|
||||
* @param callable(TValue, TValue): int $function
|
||||
* @return void
|
||||
*/
|
||||
public function uasort($function)
|
||||
@@ -424,7 +430,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
/**
|
||||
* Sort the entries by keys using a user-defined comparison function
|
||||
*
|
||||
* @param callable $function
|
||||
* @param callable(TKey, TKey): int $function
|
||||
* @return void
|
||||
*/
|
||||
public function uksort($function)
|
||||
@@ -486,9 +492,7 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'Cannot deserialize %s instance: invalid iteratorClass; expected string, received %s',
|
||||
self::class,
|
||||
is_object($data['iteratorClass'])
|
||||
? get_class($data['iteratorClass'])
|
||||
: gettype($data['iteratorClass'])
|
||||
get_debug_type($data['iteratorClass'])
|
||||
));
|
||||
}
|
||||
$this->setIteratorClass($data['iteratorClass']);
|
||||
|
||||
@@ -9,7 +9,6 @@ interface ArraySerializableInterface
|
||||
/**
|
||||
* Exchange internal values from provided array
|
||||
*
|
||||
* @param array $array
|
||||
* @return void
|
||||
*/
|
||||
public function exchangeArray(array $array);
|
||||
|
||||
@@ -12,6 +12,10 @@ use function array_reverse;
|
||||
|
||||
/**
|
||||
* ArrayObject that acts as a stack with regards to iteration
|
||||
*
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
* @template-extends PhpArrayObject<TKey, TValue>
|
||||
*/
|
||||
class ArrayStack extends PhpArrayObject
|
||||
{
|
||||
@@ -21,7 +25,7 @@ class ArrayStack extends PhpArrayObject
|
||||
* Retrieve an array copy of the object, reverse its order, and return an
|
||||
* ArrayIterator with that reversed array.
|
||||
*
|
||||
* @return ArrayIterator
|
||||
* @return ArrayIterator<TKey, TValue>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
|
||||
@@ -35,22 +35,25 @@ abstract class ArrayUtils
|
||||
{
|
||||
/**
|
||||
* Compatibility Flag for ArrayUtils::filter
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public const ARRAY_FILTER_USE_BOTH = 1;
|
||||
|
||||
/**
|
||||
* Compatibility Flag for ArrayUtils::filter
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public const ARRAY_FILTER_USE_KEY = 2;
|
||||
|
||||
/**
|
||||
* Test whether an array contains one or more string keys
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param bool $allowEmpty Should an empty array() return true
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasStringKeys($value, $allowEmpty = false)
|
||||
public static function hasStringKeys(mixed $value, $allowEmpty = false)
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return false;
|
||||
@@ -66,11 +69,10 @@ abstract class ArrayUtils
|
||||
/**
|
||||
* Test whether an array contains one or more integer keys
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param bool $allowEmpty Should an empty array() return true
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasIntegerKeys($value, $allowEmpty = false)
|
||||
public static function hasIntegerKeys(mixed $value, $allowEmpty = false)
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return false;
|
||||
@@ -93,11 +95,10 @@ abstract class ArrayUtils
|
||||
* - a float: 2.2120, -78.150999
|
||||
* - a string with float: '4000.99999', '-10.10'
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param bool $allowEmpty Should an empty array() return true
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasNumericKeys($value, $allowEmpty = false)
|
||||
public static function hasNumericKeys(mixed $value, $allowEmpty = false)
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return false;
|
||||
@@ -126,11 +127,10 @@ abstract class ArrayUtils
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param bool $allowEmpty Is an empty list a valid list?
|
||||
* @return bool
|
||||
*/
|
||||
public static function isList($value, $allowEmpty = false)
|
||||
public static function isList(mixed $value, $allowEmpty = false)
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return false;
|
||||
@@ -168,11 +168,10 @@ abstract class ArrayUtils
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param bool $allowEmpty Is an empty array() a valid hash table?
|
||||
* @return bool
|
||||
*/
|
||||
public static function isHashTable($value, $allowEmpty = false)
|
||||
public static function isHashTable(mixed $value, $allowEmpty = false)
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return false;
|
||||
@@ -193,14 +192,15 @@ abstract class ArrayUtils
|
||||
* non-strict check is implemented. if $strict = -1, the default in_array
|
||||
* non-strict behaviour is used.
|
||||
*
|
||||
* @param mixed $needle
|
||||
* @deprecated This method will be removed in version 4.0 of this component
|
||||
*
|
||||
* @param array $haystack
|
||||
* @param int|bool $strict
|
||||
* @return bool
|
||||
*/
|
||||
public static function inArray($needle, array $haystack, $strict = false)
|
||||
public static function inArray(mixed $needle, array $haystack, $strict = false)
|
||||
{
|
||||
if (! $strict) {
|
||||
if ((bool) $strict === false) {
|
||||
if (is_int($needle) || is_float($needle)) {
|
||||
$needle = (string) $needle;
|
||||
}
|
||||
@@ -318,7 +318,6 @@ abstract class ArrayUtils
|
||||
/**
|
||||
* @deprecated Since 3.2.0; use the native array_filter methods
|
||||
*
|
||||
* @param array $data
|
||||
* @param callable $callback
|
||||
* @param null|int $flag
|
||||
* @return array
|
||||
|
||||
@@ -6,15 +6,8 @@ namespace Laminas\Stdlib\ArrayUtils;
|
||||
|
||||
final class MergeReplaceKey implements MergeReplaceKeyInterface
|
||||
{
|
||||
/** @var mixed */
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*/
|
||||
public function __construct($data)
|
||||
public function __construct(protected mixed $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ abstract class ErrorHandler
|
||||
/**
|
||||
* Active stack
|
||||
*
|
||||
* @var array
|
||||
* @var list<ErrorException|null>
|
||||
*/
|
||||
protected static $stack = [];
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ use function unserialize;
|
||||
* elements from the queue and it also acts like an Iterator without removing
|
||||
* the elements. This behaviour can be used in mixed scenarios with high
|
||||
* performance boost.
|
||||
*
|
||||
* @template TValue of mixed
|
||||
* @template-implements Iterator<int, TValue>
|
||||
*/
|
||||
class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
{
|
||||
@@ -37,20 +40,20 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
public const EXTR_PRIORITY = PhpSplPriorityQueue::EXTR_PRIORITY;
|
||||
public const EXTR_BOTH = PhpSplPriorityQueue::EXTR_BOTH;
|
||||
|
||||
/** @var integer */
|
||||
/** @var self::EXTR_* */
|
||||
protected $extractFlag = self::EXTR_DATA;
|
||||
|
||||
/**
|
||||
* Elements of the queue, divided by priorities
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, list<TValue>>
|
||||
*/
|
||||
protected $values = [];
|
||||
|
||||
/**
|
||||
* Array of priorities
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, int>
|
||||
*/
|
||||
protected $priorities = [];
|
||||
|
||||
@@ -64,28 +67,28 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
/**
|
||||
* Max priority
|
||||
*
|
||||
* @var integer|null
|
||||
* @var int|null
|
||||
*/
|
||||
protected $maxPriority;
|
||||
|
||||
/**
|
||||
* Total number of elements in the queue
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $count = 0;
|
||||
|
||||
/**
|
||||
* Index of the current element in the queue
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $index = 0;
|
||||
|
||||
/**
|
||||
* Sub index of the current element in the same priority level
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $subIndex = 0;
|
||||
|
||||
@@ -112,11 +115,11 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
/**
|
||||
* Insert an element in the queue with a specified priority
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param integer $priority
|
||||
* @param TValue $value
|
||||
* @param int $priority
|
||||
* @return void
|
||||
*/
|
||||
public function insert($value, $priority)
|
||||
public function insert(mixed $value, $priority)
|
||||
{
|
||||
if (! is_int($priority)) {
|
||||
throw new Exception\InvalidArgumentException('The priority must be an integer');
|
||||
@@ -133,7 +136,7 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
* Extract an element in the queue according to the priority and the
|
||||
* order of insertion
|
||||
*
|
||||
* @return mixed
|
||||
* @return TValue|int|array{data: TValue, priority: int}|false
|
||||
*/
|
||||
public function extract()
|
||||
{
|
||||
@@ -155,10 +158,9 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
* the same item has been added multiple times, it will not remove other
|
||||
* instances.
|
||||
*
|
||||
* @param mixed $datum
|
||||
* @return bool False if the item was not found, true otherwise.
|
||||
*/
|
||||
public function remove($datum)
|
||||
public function remove(mixed $datum)
|
||||
{
|
||||
$currentIndex = $this->index;
|
||||
$currentSubIndex = $this->subIndex;
|
||||
@@ -211,7 +213,7 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
/**
|
||||
* Get the current element in the queue
|
||||
*
|
||||
* @return mixed
|
||||
* @return TValue|int|array{data: TValue|false, priority: int|null}|false
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function current()
|
||||
@@ -308,7 +310,7 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
*
|
||||
* Array will be priority => data pairs
|
||||
*
|
||||
* @return array
|
||||
* @return list<TValue|int|array{data: TValue, priority: int}>
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
@@ -351,26 +353,21 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
/**
|
||||
* Set the extract flag
|
||||
*
|
||||
* @param integer $flag
|
||||
* @param self::EXTR_* $flag
|
||||
* @return void
|
||||
*/
|
||||
public function setExtractFlags($flag)
|
||||
{
|
||||
switch ($flag) {
|
||||
case self::EXTR_DATA:
|
||||
case self::EXTR_PRIORITY:
|
||||
case self::EXTR_BOTH:
|
||||
$this->extractFlag = $flag;
|
||||
break;
|
||||
default:
|
||||
throw new Exception\InvalidArgumentException("The extract flag specified is not valid");
|
||||
}
|
||||
$this->extractFlag = match ($flag) {
|
||||
self::EXTR_DATA, self::EXTR_PRIORITY, self::EXTR_BOTH => $flag,
|
||||
default => throw new Exception\InvalidArgumentException("The extract flag specified is not valid"),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the queue is empty
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
@@ -380,10 +377,9 @@ class FastPriorityQueue implements Iterator, Countable, Serializable
|
||||
/**
|
||||
* Does the queue contain the given datum?
|
||||
*
|
||||
* @param mixed $datum
|
||||
* @return bool
|
||||
*/
|
||||
public function contains($datum)
|
||||
public function contains(mixed $datum)
|
||||
{
|
||||
foreach ($this->values as $values) {
|
||||
if (in_array($datum, $values)) {
|
||||
|
||||
@@ -8,10 +8,8 @@ use Exception;
|
||||
use Laminas\Stdlib\Exception\InvalidArgumentException;
|
||||
use Traversable;
|
||||
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function get_debug_type;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
@@ -29,7 +27,7 @@ trait ArrayOrTraversableGuardTrait
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function guardForArrayOrTraversable(
|
||||
$data,
|
||||
mixed $data,
|
||||
$dataName = 'Argument',
|
||||
$exceptionClass = InvalidArgumentException::class
|
||||
) {
|
||||
@@ -37,7 +35,7 @@ trait ArrayOrTraversableGuardTrait
|
||||
$message = sprintf(
|
||||
"%s must be an array or Traversable, [%s] given",
|
||||
$dataName,
|
||||
is_object($data) ? get_class($data) : gettype($data)
|
||||
get_debug_type($data)
|
||||
);
|
||||
throw new $exceptionClass($message);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ trait EmptyGuardTrait
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function guardAgainstEmpty(
|
||||
$data,
|
||||
mixed $data,
|
||||
$dataName = 'Argument',
|
||||
$exceptionClass = InvalidArgumentException::class
|
||||
) {
|
||||
|
||||
@@ -24,7 +24,7 @@ trait NullGuardTrait
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function guardAgainstNull(
|
||||
$data,
|
||||
mixed $data,
|
||||
$dataName = 'Argument',
|
||||
$exceptionClass = InvalidArgumentException::class
|
||||
) {
|
||||
|
||||
@@ -7,10 +7,8 @@ namespace Laminas\Stdlib;
|
||||
use Traversable;
|
||||
|
||||
use function array_key_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function get_debug_type;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_scalar;
|
||||
use function sprintf;
|
||||
|
||||
@@ -42,7 +40,7 @@ class Message implements MessageInterface
|
||||
if (! is_array($spec) && ! $spec instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Expected a string, array, or Traversable argument in first position; received "%s"',
|
||||
is_object($spec) ? get_class($spec) : gettype($spec)
|
||||
get_debug_type($spec)
|
||||
));
|
||||
}
|
||||
foreach ($spec as $key => $value) {
|
||||
|
||||
@@ -4,29 +4,33 @@ declare(strict_types=1);
|
||||
|
||||
namespace Laminas\Stdlib;
|
||||
|
||||
/**
|
||||
* @template TKey of string
|
||||
* @template TValue
|
||||
*/
|
||||
interface ParameterObjectInterface
|
||||
{
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param TKey $key
|
||||
* @param TValue|null $value
|
||||
* @return void
|
||||
*/
|
||||
public function __set($key, $value);
|
||||
public function __set($key, mixed $value);
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @param TKey $key
|
||||
* @return TValue
|
||||
*/
|
||||
public function __get($key);
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param TKey $key
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($key);
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param TKey $key
|
||||
* @return void
|
||||
*/
|
||||
public function __unset($key);
|
||||
|
||||
@@ -10,6 +10,12 @@ use ReturnTypeWillChange;
|
||||
use function http_build_query;
|
||||
use function parse_str;
|
||||
|
||||
/**
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
* @template-extends PhpArrayObject<TKey, TValue>
|
||||
* @template-implements ParametersInterface<TKey, TValue>
|
||||
*/
|
||||
class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
{
|
||||
/**
|
||||
@@ -18,7 +24,7 @@ class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
* Enforces that we have an array, and enforces parameter access to array
|
||||
* elements.
|
||||
*
|
||||
* @param array $values
|
||||
* @param array<TKey, TValue>|null $values
|
||||
*/
|
||||
public function __construct(?array $values = null)
|
||||
{
|
||||
@@ -31,7 +37,7 @@ class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
/**
|
||||
* Populate from native PHP array
|
||||
*
|
||||
* @param array $values
|
||||
* @param array<TKey, TValue> $values
|
||||
* @return void
|
||||
*/
|
||||
public function fromArray(array $values)
|
||||
@@ -55,7 +61,7 @@ class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
/**
|
||||
* Serialize to native PHP array
|
||||
*
|
||||
* @return array
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
@@ -77,8 +83,8 @@ class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
*
|
||||
* Returns null if the key does not exist.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
* @param TKey $name
|
||||
* @return TValue|null
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($name)
|
||||
@@ -91,9 +97,10 @@ class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $default optional default value
|
||||
* @return mixed
|
||||
* @template TDefault
|
||||
* @param TKey $name
|
||||
* @param TDefault $default optional default value
|
||||
* @return TValue|TDefault|null
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
@@ -104,9 +111,9 @@ class Parameters extends PhpArrayObject implements ParametersInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Parameters
|
||||
* @param TKey $name
|
||||
* @param TValue $value
|
||||
* @return $this
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
|
||||
@@ -9,17 +9,22 @@ use Countable;
|
||||
use Serializable;
|
||||
use Traversable;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Basically, an ArrayObject. You could simply define something like:
|
||||
* class QueryParams extends ArrayObject implements Parameters {}
|
||||
* and have 90% of the functionality
|
||||
*
|
||||
* @template TKey
|
||||
* @template TValue
|
||||
* @template-extends ArrayAccess<TKey, TValue>
|
||||
* @template-extends Traversable<TKey, TValue>
|
||||
*/
|
||||
interface ParametersInterface extends ArrayAccess, Countable, Serializable, Traversable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $values
|
||||
* @param array<TKey, TValue>|null $values
|
||||
*/
|
||||
public function __construct(?array $values = null);
|
||||
|
||||
@@ -28,7 +33,7 @@ interface ParametersInterface extends ArrayAccess, Countable, Serializable, Trav
|
||||
*
|
||||
* Allow deserialization from standard array
|
||||
*
|
||||
* @param array $values
|
||||
* @param array<TKey, TValue> $values
|
||||
* @return mixed
|
||||
*/
|
||||
public function fromArray(array $values);
|
||||
@@ -48,7 +53,7 @@ interface ParametersInterface extends ArrayAccess, Countable, Serializable, Trav
|
||||
*
|
||||
* Allow serialization back to standard array
|
||||
*
|
||||
* @return mixed
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public function toArray();
|
||||
|
||||
@@ -57,24 +62,20 @@ interface ParametersInterface extends ArrayAccess, Countable, Serializable, Trav
|
||||
*
|
||||
* Allow serialization to query format; e.g., for PUT or POST requests
|
||||
*
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public function toString();
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed|null $default
|
||||
* @param TKey $name
|
||||
* @param TValue|null $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name, $default = null);
|
||||
|
||||
/**
|
||||
* Set
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param TKey $name
|
||||
* @param TValue $value
|
||||
* @return ParametersInterface
|
||||
*/
|
||||
public function set($name, $value);
|
||||
|
||||
@@ -16,6 +16,11 @@ use function next;
|
||||
use function reset;
|
||||
use function uasort;
|
||||
|
||||
/**
|
||||
* @template TKey of string
|
||||
* @template TValue of mixed
|
||||
* @template-implements Iterator<TKey, TValue>
|
||||
*/
|
||||
class PriorityList implements Iterator, Countable
|
||||
{
|
||||
public const EXTR_DATA = 0x00000001;
|
||||
@@ -25,14 +30,14 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* Internal list of all items.
|
||||
*
|
||||
* @var array[]
|
||||
* @var array<TKey, array{data: TValue, priority: int, serial: positive-int|0}>
|
||||
*/
|
||||
protected $items = [];
|
||||
|
||||
/**
|
||||
* Serial assigned to items to preserve LIFO.
|
||||
*
|
||||
* @var int
|
||||
* @var positive-int|0
|
||||
*/
|
||||
protected $serial = 0;
|
||||
|
||||
@@ -64,12 +69,12 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* Insert a new item.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param int $priority
|
||||
* @param TKey $name
|
||||
* @param TValue $value
|
||||
* @param int $priority
|
||||
* @return void
|
||||
*/
|
||||
public function insert($name, $value, $priority = 0)
|
||||
public function insert($name, mixed $value, $priority = 0)
|
||||
{
|
||||
if (! isset($this->items[$name])) {
|
||||
$this->count++;
|
||||
@@ -85,7 +90,7 @@ class PriorityList implements Iterator, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param TKey $name
|
||||
* @param int $priority
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
@@ -105,7 +110,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* Remove a item.
|
||||
*
|
||||
* @param string $name
|
||||
* @param TKey $name
|
||||
* @return void
|
||||
*/
|
||||
public function remove($name)
|
||||
@@ -133,8 +138,8 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* Get a item.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
* @param TKey $name
|
||||
* @return TValue|null
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
@@ -162,7 +167,6 @@ class PriorityList implements Iterator, Countable
|
||||
* Compare the priority of two items.
|
||||
*
|
||||
* @param array $item1,
|
||||
* @param array $item2
|
||||
* @return int
|
||||
*/
|
||||
protected function compare(array $item1, array $item2)
|
||||
|
||||
@@ -12,7 +12,6 @@ use UnexpectedValueException;
|
||||
|
||||
use function array_map;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function is_array;
|
||||
use function serialize;
|
||||
use function sprintf;
|
||||
@@ -30,9 +29,9 @@ use function unserialize;
|
||||
* "inner" iterator in the form of an SplPriorityQueue object for performing
|
||||
* the actual iteration.
|
||||
*
|
||||
* @template T
|
||||
* @template TValue
|
||||
* @template TPriority of int
|
||||
* @implements IteratorAggregate<array-key, T>
|
||||
* @implements IteratorAggregate<array-key, TValue>
|
||||
*/
|
||||
class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
{
|
||||
@@ -51,14 +50,14 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
* Actual items aggregated in the priority queue. Each item is an array
|
||||
* with keys "data" and "priority".
|
||||
*
|
||||
* @var list<array{data: T, priority: TPriority}>
|
||||
* @var list<array{data: TValue, priority: TPriority}>
|
||||
*/
|
||||
protected $items = [];
|
||||
|
||||
/**
|
||||
* Inner queue object
|
||||
*
|
||||
* @var \SplPriorityQueue<TPriority, T>|null
|
||||
* @var \SplPriorityQueue<TPriority, TValue>|null
|
||||
*/
|
||||
protected $queue;
|
||||
|
||||
@@ -67,7 +66,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
*
|
||||
* Priority defaults to 1 (low priority) if none provided.
|
||||
*
|
||||
* @param T $data
|
||||
* @param TValue $data
|
||||
* @param TPriority $priority
|
||||
* @return $this
|
||||
*/
|
||||
@@ -96,10 +95,9 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
* the same item has been added multiple times, it will not remove other
|
||||
* instances.
|
||||
*
|
||||
* @param mixed $datum
|
||||
* @return bool False if the item was not found, true otherwise.
|
||||
*/
|
||||
public function remove($datum)
|
||||
public function remove(mixed $datum)
|
||||
{
|
||||
$found = false;
|
||||
$key = null;
|
||||
@@ -148,7 +146,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
/**
|
||||
* Peek at the top node in the queue, based on priority.
|
||||
*
|
||||
* @return T
|
||||
* @return TValue
|
||||
*/
|
||||
public function top()
|
||||
{
|
||||
@@ -160,7 +158,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
/**
|
||||
* Extract a node from the inner queue and sift up
|
||||
*
|
||||
* @return T
|
||||
* @return TValue
|
||||
*/
|
||||
public function extract()
|
||||
{
|
||||
@@ -204,7 +202,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
* retrieves the inner queue object, and clones it for purposes of
|
||||
* iteration.
|
||||
*
|
||||
* @return \SplPriorityQueue<TPriority, T>
|
||||
* @return \SplPriorityQueue<TPriority, TValue>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
@@ -226,7 +224,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
/**
|
||||
* Magic method used for serializing of an instance.
|
||||
*
|
||||
* @return list<array{data: T, priority: TPriority}>
|
||||
* @return list<array{data: TValue, priority: TPriority}>
|
||||
*/
|
||||
public function __serialize()
|
||||
{
|
||||
@@ -251,7 +249,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
));
|
||||
}
|
||||
|
||||
/** @psalm-var list<array{data: T, priority: TPriority}> $toUnserialize */
|
||||
/** @psalm-var list<array{data: TValue, priority: TPriority}> $toUnserialize */
|
||||
|
||||
$this->__unserialize($toUnserialize);
|
||||
}
|
||||
@@ -259,7 +257,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
/**
|
||||
* Magic method used to rebuild an instance.
|
||||
*
|
||||
* @param list<array{data: T, priority: TPriority}> $data Data array.
|
||||
* @param list<array{data: TValue, priority: TPriority}> $data Data array.
|
||||
* @return void
|
||||
*/
|
||||
public function __unserialize($data)
|
||||
@@ -278,23 +276,19 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
* @param int $flag
|
||||
* @return array<array-key, mixed>
|
||||
* @psalm-return ($flag is self::EXTR_BOTH
|
||||
* ? list<array{data: T, priority: TPriority}>
|
||||
* ? list<array{data: TValue, priority: TPriority}>
|
||||
* : $flag is self::EXTR_PRIORITY
|
||||
* ? list<TPriority>
|
||||
* : list<T>
|
||||
* : list<TValue>
|
||||
* )
|
||||
*/
|
||||
public function toArray($flag = self::EXTR_DATA)
|
||||
{
|
||||
switch ($flag) {
|
||||
case self::EXTR_BOTH:
|
||||
return $this->items;
|
||||
case self::EXTR_PRIORITY:
|
||||
return array_map(static fn($item) => $item['priority'], $this->items);
|
||||
case self::EXTR_DATA:
|
||||
default:
|
||||
return array_map(static fn($item) => $item['data'], $this->items);
|
||||
}
|
||||
return match ($flag) {
|
||||
self::EXTR_BOTH => $this->items,
|
||||
self::EXTR_PRIORITY => array_map(static fn($item): int => $item['priority'], $this->items),
|
||||
default => array_map(static fn($item): mixed => $item['data'], $this->items),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +310,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
/**
|
||||
* Does the queue contain the given datum?
|
||||
*
|
||||
* @param T $datum
|
||||
* @param TValue $datum
|
||||
* @return bool
|
||||
*/
|
||||
public function contains($datum)
|
||||
@@ -349,7 +343,7 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
* Get the inner priority queue instance
|
||||
*
|
||||
* @throws Exception\DomainException
|
||||
* @return \SplPriorityQueue<TPriority, T>
|
||||
* @return \SplPriorityQueue<TPriority, TValue>
|
||||
* @psalm-assert !null $this->queue
|
||||
*/
|
||||
protected function getQueue()
|
||||
@@ -357,13 +351,13 @@ class PriorityQueue implements Countable, IteratorAggregate, Serializable
|
||||
if (null === $this->queue) {
|
||||
/** @psalm-suppress UnsafeInstantiation */
|
||||
$queue = new $this->queueClass();
|
||||
/** @psalm-var \SplPriorityQueue<TPriority, T> $queue */
|
||||
/** @psalm-var \SplPriorityQueue<TPriority, TValue> $queue */
|
||||
$this->queue = $queue;
|
||||
/** @psalm-suppress DocblockTypeContradiction, MixedArgument */
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if (! $this->queue instanceof \SplPriorityQueue) {
|
||||
throw new Exception\DomainException(sprintf(
|
||||
'PriorityQueue expects an internal queue of type SplPriorityQueue; received "%s"',
|
||||
get_class($this->queue)
|
||||
$queue::class
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Laminas\Stdlib;
|
||||
|
||||
use ReturnTypeWillChange;
|
||||
use Serializable;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_key_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function get_debug_type;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function serialize;
|
||||
use function sprintf;
|
||||
use function unserialize;
|
||||
@@ -24,9 +23,8 @@ use const PHP_INT_MAX;
|
||||
* Also, provides predictable heap order for datums added with the same priority
|
||||
* (i.e., they will be emitted in the same order they are enqueued).
|
||||
*
|
||||
* @psalm-type InternalPriority = array{0: mixed, 1: int}
|
||||
* @template TValue
|
||||
* @template TPriority of InternalPriority
|
||||
* @template TPriority of int
|
||||
* @extends \SplPriorityQueue<TPriority, TValue>
|
||||
*/
|
||||
class SplPriorityQueue extends \SplPriorityQueue implements Serializable
|
||||
@@ -40,19 +38,18 @@ class SplPriorityQueue extends \SplPriorityQueue implements Serializable
|
||||
* Utilizes {@var $serial} to ensure that values of equal priority are
|
||||
* emitted in the same order in which they are inserted.
|
||||
*
|
||||
* @param TValue $datum
|
||||
* @param TPriority|mixed $priority
|
||||
* @param TValue $value
|
||||
* @param TPriority $priority
|
||||
* @return void
|
||||
*/
|
||||
public function insert($datum, $priority)
|
||||
#[ReturnTypeWillChange] // Inherited return type should be bool
|
||||
public function insert($value, $priority)
|
||||
{
|
||||
if (! is_array($priority)) {
|
||||
$priority = [$priority, $this->serial--];
|
||||
}
|
||||
|
||||
/** @psalm-var TPriority $priority */
|
||||
|
||||
parent::insert($datum, $priority);
|
||||
parent::insert($value, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +117,7 @@ class SplPriorityQueue extends \SplPriorityQueue implements Serializable
|
||||
/**
|
||||
* Magic method used to rebuild an instance.
|
||||
*
|
||||
* @param array $data Data array.
|
||||
* @param array<array-key, mixed> $data Data array.
|
||||
* @return void
|
||||
*/
|
||||
public function __unserialize($data)
|
||||
@@ -132,7 +129,7 @@ class SplPriorityQueue extends \SplPriorityQueue implements Serializable
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'Cannot deserialize %s instance: corrupt item; expected array, received %s',
|
||||
self::class,
|
||||
is_object($item) ? get_class($item) : gettype($item)
|
||||
get_debug_type($item)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -148,8 +145,6 @@ class SplPriorityQueue extends \SplPriorityQueue implements Serializable
|
||||
$priority = (int) $item['priority'];
|
||||
}
|
||||
|
||||
/** @psalm-var TValue $item['data'] */
|
||||
|
||||
$this->insert($item['data'], $priority);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user