mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
N°5122 - Update libs to new PHP requirements
This commit is contained in:
@@ -1,17 +1,31 @@
|
||||
<?php
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.AbstractClass.Prefix
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-stdlib for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-stdlib/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-stdlib/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laminas\Stdlib;
|
||||
|
||||
use Iterator;
|
||||
use Laminas\Stdlib\ArrayUtils\MergeRemoveKey;
|
||||
use Laminas\Stdlib\ArrayUtils\MergeReplaceKeyInterface;
|
||||
use Traversable;
|
||||
|
||||
use function array_filter;
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function array_values;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
use function is_float;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function is_scalar;
|
||||
use function is_string;
|
||||
use function iterator_to_array;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Utility class for testing and manipulation of PHP arrays.
|
||||
*
|
||||
@@ -22,12 +36,12 @@ abstract class ArrayUtils
|
||||
/**
|
||||
* Compatibility Flag for ArrayUtils::filter
|
||||
*/
|
||||
const ARRAY_FILTER_USE_BOTH = 1;
|
||||
public const ARRAY_FILTER_USE_BOTH = 1;
|
||||
|
||||
/**
|
||||
* Compatibility Flag for ArrayUtils::filter
|
||||
*/
|
||||
const ARRAY_FILTER_USE_KEY = 2;
|
||||
public const ARRAY_FILTER_USE_KEY = 2;
|
||||
|
||||
/**
|
||||
* Test whether an array contains one or more string keys
|
||||
@@ -46,7 +60,7 @@ abstract class ArrayUtils
|
||||
return $allowEmpty;
|
||||
}
|
||||
|
||||
return count(array_filter(array_keys($value), 'is_string')) > 0;
|
||||
return [] !== array_filter(array_keys($value), 'is_string');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +80,7 @@ abstract class ArrayUtils
|
||||
return $allowEmpty;
|
||||
}
|
||||
|
||||
return count(array_filter(array_keys($value), 'is_int')) > 0;
|
||||
return [] !== array_filter(array_keys($value), 'is_int');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +107,7 @@ abstract class ArrayUtils
|
||||
return $allowEmpty;
|
||||
}
|
||||
|
||||
return count(array_filter(array_keys($value), 'is_numeric')) > 0;
|
||||
return [] !== array_filter(array_keys($value), 'is_numeric');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +140,7 @@ abstract class ArrayUtils
|
||||
return $allowEmpty;
|
||||
}
|
||||
|
||||
return (array_values($value) === $value);
|
||||
return array_values($value) === $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +182,7 @@ abstract class ArrayUtils
|
||||
return $allowEmpty;
|
||||
}
|
||||
|
||||
return (array_values($value) !== $value);
|
||||
return array_values($value) !== $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,22 +212,24 @@ abstract class ArrayUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
return in_array($needle, $haystack, $strict);
|
||||
|
||||
return in_array($needle, $haystack, (bool) $strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an iterator to an array.
|
||||
*
|
||||
* Converts an iterator to an array. The $recursive flag, on by default,
|
||||
* hints whether or not you want to do so recursively.
|
||||
*
|
||||
* @param array|Traversable $iterator The array or Traversable object to convert
|
||||
* @param bool $recursive Recursively check all nested structures
|
||||
* @throws Exception\InvalidArgumentException if $iterator is not an array or a Traversable object
|
||||
* @return array
|
||||
* @template TKey
|
||||
* @template TValue
|
||||
* @param iterable<TKey, TValue> $iterator The array or Traversable object to convert
|
||||
* @param bool $recursive Recursively check all nested structures
|
||||
* @throws Exception\InvalidArgumentException If $iterator is not an array or a Traversable object.
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function iteratorToArray($iterator, $recursive = true)
|
||||
{
|
||||
/** @psalm-suppress DocblockTypeContradiction */
|
||||
if (! is_array($iterator) && ! $iterator instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object');
|
||||
}
|
||||
@@ -226,8 +242,15 @@ abstract class ArrayUtils
|
||||
return iterator_to_array($iterator);
|
||||
}
|
||||
|
||||
if (method_exists($iterator, 'toArray')) {
|
||||
return $iterator->toArray();
|
||||
if (
|
||||
is_object($iterator)
|
||||
&& ! $iterator instanceof Iterator
|
||||
&& method_exists($iterator, 'toArray')
|
||||
) {
|
||||
/** @psalm-var array<TKey, TValue> $array */
|
||||
$array = $iterator->toArray();
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
$array = [];
|
||||
@@ -250,6 +273,8 @@ abstract class ArrayUtils
|
||||
$array[$key] = $value;
|
||||
}
|
||||
|
||||
/** @psalm-var array<TKey, TValue> $array */
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -308,6 +333,6 @@ abstract class ArrayUtils
|
||||
));
|
||||
}
|
||||
|
||||
return array_filter($data, $callback, $flag);
|
||||
return array_filter($data, $callback, $flag ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user