mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-21 16:22:20 +02:00
N°5122 - Update libs to new PHP requirements
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @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 Countable;
|
||||
use Exception;
|
||||
use Iterator;
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
use function array_map;
|
||||
use function current;
|
||||
use function key;
|
||||
use function next;
|
||||
use function reset;
|
||||
use function uasort;
|
||||
|
||||
class PriorityList implements Iterator, Countable
|
||||
{
|
||||
const EXTR_DATA = 0x00000001;
|
||||
const EXTR_PRIORITY = 0x00000002;
|
||||
const EXTR_BOTH = 0x00000003;
|
||||
public const EXTR_DATA = 0x00000001;
|
||||
public const EXTR_PRIORITY = 0x00000002;
|
||||
public const EXTR_BOTH = 0x00000003;
|
||||
|
||||
/**
|
||||
* Internal list of all items.
|
||||
*
|
||||
@@ -30,12 +36,17 @@ class PriorityList implements Iterator, Countable
|
||||
*/
|
||||
protected $serial = 0;
|
||||
|
||||
// phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCapsProperty
|
||||
|
||||
/**
|
||||
* Serial order mode
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $isLIFO = 1;
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Internal counter to avoid usage of count().
|
||||
*
|
||||
@@ -56,7 +67,6 @@ class PriorityList implements Iterator, Countable
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @param int $priority
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function insert($name, $value, $priority = 0)
|
||||
@@ -77,15 +87,13 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $priority
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setPriority($name, $priority)
|
||||
{
|
||||
if (! isset($this->items[$name])) {
|
||||
throw new \Exception("item $name not found");
|
||||
throw new Exception("item $name not found");
|
||||
}
|
||||
|
||||
$this->items[$name]['priority'] = (int) $priority;
|
||||
@@ -159,7 +167,7 @@ class PriorityList implements Iterator, Countable
|
||||
*/
|
||||
protected function compare(array $item1, array $item2)
|
||||
{
|
||||
return ($item1['priority'] === $item2['priority'])
|
||||
return $item1['priority'] === $item2['priority']
|
||||
? ($item1['serial'] > $item2['serial'] ? -1 : 1) * $this->isLIFO
|
||||
: ($item1['priority'] > $item2['priority'] ? -1 : 1);
|
||||
}
|
||||
@@ -168,7 +176,6 @@ class PriorityList implements Iterator, Countable
|
||||
* Get/Set serial order mode
|
||||
*
|
||||
* @param bool|null $flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLIFO($flag = null)
|
||||
@@ -188,6 +195,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
{
|
||||
$this->sort();
|
||||
@@ -197,6 +205,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
$this->sorted || $this->sort();
|
||||
@@ -208,6 +217,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
$this->sorted || $this->sort();
|
||||
@@ -217,6 +227,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function next()
|
||||
{
|
||||
$node = next($this->items);
|
||||
@@ -227,6 +238,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function valid()
|
||||
{
|
||||
return current($this->items) !== false;
|
||||
@@ -243,6 +255,7 @@ class PriorityList implements Iterator, Countable
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return $this->count;
|
||||
@@ -252,20 +265,19 @@ class PriorityList implements Iterator, Countable
|
||||
* Return list as array
|
||||
*
|
||||
* @param int $flag
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($flag = self::EXTR_DATA)
|
||||
{
|
||||
$this->sort();
|
||||
|
||||
if ($flag == self::EXTR_BOTH) {
|
||||
if ($flag === self::EXTR_BOTH) {
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
return array_map(
|
||||
function ($item) use ($flag) {
|
||||
return ($flag == PriorityList::EXTR_PRIORITY) ? $item['priority'] : $item['data'];
|
||||
return $flag === PriorityList::EXTR_PRIORITY ? $item['priority'] : $item['data'];
|
||||
},
|
||||
$this->items
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user