Aggiornato Composer
This commit is contained in:
@@ -17,6 +17,7 @@ namespace Ramsey\Collection;
|
||||
use ArrayIterator;
|
||||
use Traversable;
|
||||
|
||||
use function count;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
||||
@@ -34,7 +35,7 @@ abstract class AbstractArray implements ArrayInterface
|
||||
*
|
||||
* @var array<array-key, T>
|
||||
*/
|
||||
protected $data = [];
|
||||
protected array $data = [];
|
||||
|
||||
/**
|
||||
* Constructs a new array object.
|
||||
@@ -83,8 +84,6 @@ abstract class AbstractArray implements ArrayInterface
|
||||
*
|
||||
* @return T|null the value stored at the offset, or null if the offset
|
||||
* does not exist.
|
||||
*
|
||||
* @psalm-suppress InvalidAttribute
|
||||
*/
|
||||
#[\ReturnTypeWillChange] // phpcs:ignore
|
||||
public function offsetGet($offset)
|
||||
|
||||
@@ -33,7 +33,9 @@ use function current;
|
||||
use function end;
|
||||
use function in_array;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function reset;
|
||||
use function spl_object_id;
|
||||
use function sprintf;
|
||||
use function unserialize;
|
||||
use function usort;
|
||||
@@ -78,7 +80,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt
|
||||
if ($this->checkType($this->getType(), $value) === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Value must be of type ' . $this->getType() . '; value is '
|
||||
. $this->toolValueToString($value)
|
||||
. $this->toolValueToString($value),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,7 +97,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt
|
||||
public function remove($element): bool
|
||||
{
|
||||
if (($position = array_search($element, $this->data, true)) !== false) {
|
||||
unset($this->data[$position]);
|
||||
unset($this[$position]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -176,7 +178,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt
|
||||
$bValue = $this->extractValue($b, $propertyOrMethod);
|
||||
|
||||
return ($aValue <=> $bValue) * ($order === self::SORT_DESC ? -1 : 1);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return $collection;
|
||||
@@ -244,15 +246,19 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt
|
||||
foreach ($collections as $index => $collection) {
|
||||
if (!$collection instanceof static) {
|
||||
throw new CollectionMismatchException(
|
||||
sprintf('Collection with index %d must be of type %s', $index, static::class)
|
||||
sprintf('Collection with index %d must be of type %s', $index, static::class),
|
||||
);
|
||||
}
|
||||
|
||||
// When using generics (Collection.php, Set.php, etc),
|
||||
// we also need to make sure that the internal types match each other
|
||||
if ($collection->getType() !== $this->getType()) {
|
||||
if ($this->getUniformType($collection) !== $this->getUniformType($this)) {
|
||||
throw new CollectionMismatchException(
|
||||
sprintf('Collection items in collection with index %d must be of type %s', $index, $this->getType())
|
||||
sprintf(
|
||||
'Collection items in collection with index %d must be of type %s',
|
||||
$index,
|
||||
$this->getType(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -290,7 +296,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt
|
||||
|
||||
// When using generics (Collection.php, Set.php, etc),
|
||||
// we also need to make sure that the internal types match each other
|
||||
if ($other->getType() !== $this->getType()) {
|
||||
if ($this->getUniformType($other) !== $this->getUniformType($this)) {
|
||||
throw new CollectionMismatchException('Collection items must be of type ' . $this->getType());
|
||||
}
|
||||
}
|
||||
@@ -315,4 +321,21 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt
|
||||
return $a === $b ? 0 : ($a < $b ? 1 : -1);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionInterface<mixed> $collection
|
||||
*/
|
||||
private function getUniformType(CollectionInterface $collection): string
|
||||
{
|
||||
switch ($collection->getType()) {
|
||||
case 'integer':
|
||||
return 'int';
|
||||
case 'boolean':
|
||||
return 'bool';
|
||||
case 'double':
|
||||
return 'float';
|
||||
default:
|
||||
return $collection->getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
vendor/ramsey/collection/src/Collection.php
vendored
4
vendor/ramsey/collection/src/Collection.php
vendored
@@ -80,10 +80,8 @@ class Collection extends AbstractCollection
|
||||
*
|
||||
* A collection's type is immutable once it is set. For this reason, this
|
||||
* property is set private.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $collectionType;
|
||||
private string $collectionType;
|
||||
|
||||
/**
|
||||
* Constructs a collection object of the specified type, optionally with the
|
||||
|
||||
@@ -151,6 +151,7 @@ interface CollectionInterface extends ArrayInterface
|
||||
*
|
||||
* @return CollectionInterface<T>
|
||||
*/
|
||||
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
|
||||
public function where(string $propertyOrMethod, $value): self;
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,10 +29,8 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface
|
||||
{
|
||||
/**
|
||||
* Index of the last element in the queue.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $tail = -1;
|
||||
private int $tail = -1;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
@@ -42,7 +40,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface
|
||||
if ($this->checkType($this->getType(), $value) === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Value must be of type ' . $this->getType() . '; value is '
|
||||
. $this->toolValueToString($value)
|
||||
. $this->toolValueToString($value),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,6 +50,8 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException if $element is of the wrong type
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function addFirst($element): bool
|
||||
@@ -59,7 +59,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface
|
||||
if ($this->checkType($this->getType(), $element) === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Value must be of type ' . $this->getType() . '; value is '
|
||||
. $this->toolValueToString($element)
|
||||
. $this->toolValueToString($element),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
namespace Ramsey\Collection;
|
||||
|
||||
use Ramsey\Collection\Exception\NoSuchElementException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* A linear collection that supports element insertion and removal at both ends.
|
||||
@@ -175,7 +176,7 @@ interface DoubleEndedQueueInterface extends QueueInterface
|
||||
*
|
||||
* @return bool `true` if this queue changed as a result of the call.
|
||||
*
|
||||
* @throws \RuntimeException if a queue refuses to add a particular element
|
||||
* @throws RuntimeException if a queue refuses to add a particular element
|
||||
* for any reason other than that it already contains the element.
|
||||
* Implementations should use a more-specific exception that extends
|
||||
* `\RuntimeException`.
|
||||
@@ -196,7 +197,7 @@ interface DoubleEndedQueueInterface extends QueueInterface
|
||||
*
|
||||
* @return bool `true` if this queue changed as a result of the call.
|
||||
*
|
||||
* @throws \RuntimeException if a queue refuses to add a particular element
|
||||
* @throws RuntimeException if a queue refuses to add a particular element
|
||||
* for any reason other than that it already contains the element.
|
||||
* Implementations should use a more-specific exception that extends
|
||||
* `\RuntimeException`.
|
||||
|
||||
@@ -14,9 +14,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Collection\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Thrown when attempting to operate on collections of differing types.
|
||||
*/
|
||||
class CollectionMismatchException extends \RuntimeException
|
||||
class CollectionMismatchException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Collection\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Thrown when attempting to use a sort order that is not recognized.
|
||||
*/
|
||||
class InvalidSortOrderException extends \RuntimeException
|
||||
class InvalidSortOrderException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Collection\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Thrown when attempting to access an element that does not exist.
|
||||
*/
|
||||
class NoSuchElementException extends \RuntimeException
|
||||
class NoSuchElementException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Collection\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Thrown to indicate that the requested operation is not supported.
|
||||
*/
|
||||
class UnsupportedOperationException extends \RuntimeException
|
||||
class UnsupportedOperationException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Collection\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Thrown when attempting to extract a value for a method or property that does not exist.
|
||||
*/
|
||||
class ValueExtractionException extends \RuntimeException
|
||||
class ValueExtractionException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use Ramsey\Collection\Exception\InvalidArgumentException;
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function in_array;
|
||||
use function var_export;
|
||||
|
||||
/**
|
||||
* This class provides a basic implementation of `MapInterface`, to minimize the
|
||||
@@ -39,7 +40,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
|
||||
if ($offset === null) {
|
||||
throw new InvalidArgumentException(
|
||||
'Map elements are key/value pairs; a key must be provided for '
|
||||
. 'value ' . var_export($value, true)
|
||||
. 'value ' . var_export($value, true),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,13 @@ use Ramsey\Collection\Exception\InvalidArgumentException;
|
||||
use Ramsey\Collection\Tool\TypeTrait;
|
||||
use Ramsey\Collection\Tool\ValueToStringTrait;
|
||||
|
||||
use function var_export;
|
||||
|
||||
/**
|
||||
* This class provides a basic implementation of `TypedMapInterface`, to
|
||||
* minimize the effort required to implement this interface.
|
||||
*
|
||||
* @template K
|
||||
* @template K of array-key
|
||||
* @template T
|
||||
* @extends AbstractMap<T>
|
||||
* @implements TypedMapInterface<T>
|
||||
@@ -37,33 +39,30 @@ abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface
|
||||
* @param T $value
|
||||
*
|
||||
* @inheritDoc
|
||||
*
|
||||
* @psalm-suppress MoreSpecificImplementedParamType
|
||||
*/
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if ($offset === null) {
|
||||
throw new InvalidArgumentException(
|
||||
'Map elements are key/value pairs; a key must be provided for '
|
||||
. 'value ' . var_export($value, true)
|
||||
. 'value ' . var_export($value, true),
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->checkType($this->getKeyType(), $offset) === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Key must be of type ' . $this->getKeyType() . '; key is '
|
||||
. $this->toolValueToString($offset)
|
||||
. $this->toolValueToString($offset),
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->checkType($this->getValueType(), $value) === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Value must be of type ' . $this->getValueType() . '; value is '
|
||||
. $this->toolValueToString($value)
|
||||
. $this->toolValueToString($value),
|
||||
);
|
||||
}
|
||||
|
||||
/** @psalm-suppress MixedArgumentTypeCoercion */
|
||||
parent::offsetSet($offset, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ use Ramsey\Collection\Tool\ValueToStringTrait;
|
||||
use function array_combine;
|
||||
use function array_key_exists;
|
||||
use function is_int;
|
||||
use function var_export;
|
||||
|
||||
/**
|
||||
* `NamedParameterMap` represents a mapping of values to a set of named keys
|
||||
@@ -38,7 +39,7 @@ class NamedParameterMap extends AbstractMap
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $namedParameters;
|
||||
protected array $namedParameters;
|
||||
|
||||
/**
|
||||
* Constructs a new `NamedParameterMap`.
|
||||
@@ -70,14 +71,14 @@ class NamedParameterMap extends AbstractMap
|
||||
if ($offset === null) {
|
||||
throw new InvalidArgumentException(
|
||||
'Map elements are key/value pairs; a key must be provided for '
|
||||
. 'value ' . var_export($value, true)
|
||||
. 'value ' . var_export($value, true),
|
||||
);
|
||||
}
|
||||
|
||||
if (!array_key_exists($offset, $this->namedParameters)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Attempting to set value for unconfigured parameter \''
|
||||
. $offset . '\''
|
||||
. $offset . '\'',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ class NamedParameterMap extends AbstractMap
|
||||
throw new InvalidArgumentException(
|
||||
'Value for \'' . $offset . '\' must be of type '
|
||||
. $this->namedParameters[$offset] . '; value is '
|
||||
. $this->toolValueToString($value)
|
||||
. $this->toolValueToString($value),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
13
vendor/ramsey/collection/src/Map/TypedMap.php
vendored
13
vendor/ramsey/collection/src/Map/TypedMap.php
vendored
@@ -20,7 +20,7 @@ use Ramsey\Collection\Tool\TypeTrait;
|
||||
* A `TypedMap` represents a map of elements where key and value are typed.
|
||||
*
|
||||
* Each element is identified by a key with defined type and a value of defined
|
||||
* type. The keys of the map must be unique. The values on the map can be=
|
||||
* type. The keys of the map must be unique. The values on the map can be
|
||||
* repeated but each with its own different key.
|
||||
*
|
||||
* The most common case is to use a string type key, but it's not limited to
|
||||
@@ -80,7 +80,7 @@ use Ramsey\Collection\Tool\TypeTrait;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @template K
|
||||
* @template K of array-key
|
||||
* @template T
|
||||
* @extends AbstractTypedMap<K, T>
|
||||
*/
|
||||
@@ -93,20 +93,16 @@ class TypedMap extends AbstractTypedMap
|
||||
*
|
||||
* A map key's type is immutable once it is set. For this reason, this
|
||||
* property is set private.
|
||||
*
|
||||
* @var string data type of the map key.
|
||||
*/
|
||||
private $keyType;
|
||||
private string $keyType;
|
||||
|
||||
/**
|
||||
* The data type of values stored in this collection.
|
||||
*
|
||||
* A map value's type is immutable once it is set. For this reason, this
|
||||
* property is set private.
|
||||
*
|
||||
* @var string data type of the map value.
|
||||
*/
|
||||
private $valueType;
|
||||
private string $valueType;
|
||||
|
||||
/**
|
||||
* Constructs a map object of the specified key and value types,
|
||||
@@ -121,7 +117,6 @@ class TypedMap extends AbstractTypedMap
|
||||
$this->keyType = $keyType;
|
||||
$this->valueType = $valueType;
|
||||
|
||||
/** @psalm-suppress MixedArgumentTypeCoercion */
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
|
||||
16
vendor/ramsey/collection/src/Queue.php
vendored
16
vendor/ramsey/collection/src/Queue.php
vendored
@@ -37,17 +37,13 @@ class Queue extends AbstractArray implements QueueInterface
|
||||
*
|
||||
* A queue's type is immutable once it is set. For this reason, this
|
||||
* property is set private.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $queueType;
|
||||
private string $queueType;
|
||||
|
||||
/**
|
||||
* The index of the head of the queue.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $index = 0;
|
||||
protected int $index = 0;
|
||||
|
||||
/**
|
||||
* Constructs a queue object of the specified type, optionally with the
|
||||
@@ -68,13 +64,15 @@ class Queue extends AbstractArray implements QueueInterface
|
||||
* Since arbitrary offsets may not be manipulated in a queue, this method
|
||||
* serves only to fulfill the `ArrayAccess` interface requirements. It is
|
||||
* invoked by other operations when adding values to the queue.
|
||||
*
|
||||
* @throws InvalidArgumentException if $value is of the wrong type
|
||||
*/
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if ($this->checkType($this->getType(), $value) === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'Value must be of type ' . $this->getType() . '; value is '
|
||||
. $this->toolValueToString($value)
|
||||
. $this->toolValueToString($value),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -82,6 +80,8 @@ class Queue extends AbstractArray implements QueueInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException if $value is of the wrong type
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function add($element): bool
|
||||
@@ -100,7 +100,7 @@ class Queue extends AbstractArray implements QueueInterface
|
||||
|
||||
if ($element === null) {
|
||||
throw new NoSuchElementException(
|
||||
'Can\'t return element from Queue. Queue is empty.'
|
||||
'Can\'t return element from Queue. Queue is empty.',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
namespace Ramsey\Collection;
|
||||
|
||||
use Ramsey\Collection\Exception\NoSuchElementException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* A queue is a collection in which the entities in the collection are kept in
|
||||
@@ -123,7 +124,7 @@ interface QueueInterface extends ArrayInterface
|
||||
*
|
||||
* @return bool `true` if this queue changed as a result of the call.
|
||||
*
|
||||
* @throws \RuntimeException if a queue refuses to add a particular element
|
||||
* @throws RuntimeException if a queue refuses to add a particular element
|
||||
* for any reason other than that it already contains the element.
|
||||
* Implementations should use a more-specific exception that extends
|
||||
* `\RuntimeException`.
|
||||
|
||||
4
vendor/ramsey/collection/src/Set.php
vendored
4
vendor/ramsey/collection/src/Set.php
vendored
@@ -44,10 +44,8 @@ class Set extends AbstractSet
|
||||
* The type of elements stored in this set
|
||||
*
|
||||
* A set's type is immutable. For this reason, this property is private.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $setType;
|
||||
private string $setType;
|
||||
|
||||
/**
|
||||
* Constructs a set object of the specified type, optionally with the
|
||||
|
||||
@@ -36,6 +36,7 @@ trait TypeTrait
|
||||
* @param string $type The type to check the value against.
|
||||
* @param mixed $value The value to check.
|
||||
*/
|
||||
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
|
||||
protected function checkType(string $type, $value): bool
|
||||
{
|
||||
switch ($type) {
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Ramsey\Collection\Tool;
|
||||
use Ramsey\Collection\Exception\ValueExtractionException;
|
||||
|
||||
use function get_class;
|
||||
use function is_object;
|
||||
use function method_exists;
|
||||
use function property_exists;
|
||||
use function sprintf;
|
||||
@@ -37,6 +38,7 @@ trait ValueExtractorTrait
|
||||
*
|
||||
* @throws ValueExtractionException if the method or property is not defined.
|
||||
*/
|
||||
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
|
||||
protected function extractValue($object, string $propertyOrMethod)
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
@@ -52,7 +54,8 @@ trait ValueExtractorTrait
|
||||
}
|
||||
|
||||
throw new ValueExtractionException(
|
||||
sprintf('Method or property "%s" not defined in %s', $propertyOrMethod, get_class($object))
|
||||
// phpcs:ignore SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall
|
||||
sprintf('Method or property "%s" not defined in %s', $propertyOrMethod, get_class($object)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,10 @@ use function get_resource_type;
|
||||
use function is_array;
|
||||
use function is_bool;
|
||||
use function is_callable;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function is_scalar;
|
||||
use function var_export;
|
||||
|
||||
/**
|
||||
* Provides functionality to express a value as string
|
||||
@@ -44,6 +46,7 @@ trait ValueToStringTrait
|
||||
*
|
||||
* @param mixed $value the value to return as a string.
|
||||
*/
|
||||
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
|
||||
protected function toolValueToString($value): string
|
||||
{
|
||||
// null
|
||||
@@ -89,6 +92,7 @@ trait ValueToStringTrait
|
||||
}
|
||||
|
||||
// unknown type
|
||||
// phpcs:ignore SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall
|
||||
return '(' . get_class($value) . ' Object)';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user