Collection::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Utils;
4
5
abstract class Collection implements \Iterator, \Countable, \JsonSerializable
6
{
7
    /**
8
     * @var array
9
     */
10
    private $items;
11
12
    /**
13
     * @param array $items
14
     */
15
    final protected function __construct(array $items)
16
    {
17
        $this->items = $items;
18
    }
19
20
    /**
21
     * @return mixed
22
     */
23
    public function current()
24
    {
25
        return \current($this->items);
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function next()
32
    {
33
        \next($this->items);
34
    }
35
36
    /**
37
     * @return int|mixed|string|null
38
     */
39
    public function key()
40
    {
41
        return \key($this->items);
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function valid()
48
    {
49
        return \array_key_exists($this->key(), $this->items);
50
    }
51
52
    /**
53
     * @return void
54
     */
55
    public function rewind()
56
    {
57
        \reset($this->items);
58
    }
59
60
    /**
61
     * @return int|void
62
     */
63
    public function count()
64
    {
65
        return \count($this->items);
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function jsonSerialize()
72
    {
73
        return $this->items;
74
    }
75
76
    /**
77
     * @param array $items
78
     *
79
     * @return static
80
     */
81
    public static function from(array $items)
82
    {
83
        return new static($items);
84
    }
85
}
86