| 1 | <?php |
||
| 11 | class Queue extends SplQueue implements QueueInterface, \JsonSerializable |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Adds multiples objects to the end of the Queue. |
||
| 16 | * @param CollectionInterface|array $items The objects to add to the Queue. The value can be null. |
||
| 17 | * @return $this|Queue |
||
| 18 | */ |
||
| 19 | 1 | public function enqueueMultiple($items) |
|
| 20 | { |
||
| 21 | 1 | foreach ($items as $item) { |
|
|
|
|||
| 22 | 1 | $this->enqueue($item); |
|
| 23 | } |
||
| 24 | |||
| 25 | 1 | return $this; |
|
| 26 | } |
||
| 27 | |||
| 28 | public static function fromArray(array $arr) |
||
| 29 | { |
||
| 30 | $collection = new Queue(); |
||
| 31 | foreach ($arr as $v) { |
||
| 32 | if (is_array($v)) { |
||
| 33 | $collection->enqueue(static::fromArray($v)); |
||
| 34 | } else { |
||
| 35 | $collection->enqueue($v); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | return $collection; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | 2 | public function toArray() |
|
| 46 | { |
||
| 47 | 2 | $array = array(); |
|
| 48 | 2 | foreach ($this as $key => $value) { |
|
| 49 | 2 | if ($value instanceof CollectionConvertableInterface) { |
|
| 50 | $array[$key] = $value->toArray(); |
||
| 51 | } else { |
||
| 52 | 2 | $array[$key] = $value; |
|
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | 2 | return $array; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | 2 | public function __toString() |
|
| 66 | |||
| 67 | /** |
||
| 68 | * (PHP 5 >= 5.4.0)<br/> |
||
| 69 | * Specify data which should be serialized to JSON |
||
| 70 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
| 71 | * @return mixed data which can be serialized by <b>json_encode</b>, |
||
| 72 | * which is a value of any type other than a resource. |
||
| 73 | */ |
||
| 74 | public function jsonSerialize() |
||
| 78 | } |
||
| 79 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.