Collection::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi;
6
7
use ArrayIterator;
8
use Countable;
9
use Iterator;
10
use IteratorAggregate;
11
12
abstract class Collection implements Definition, Countable, IteratorAggregate
13
{
14 9
    final public function count(): int
15
    {
16 9
        return count($this->getItems());
17
    }
18
19
    abstract public function getItems(): array;
20
21 1
    final public function getIterator(): Iterator
22
    {
23 1
        return new ArrayIterator($this->getItems());
24
    }
25
26 8
    final public function hasItems(): bool
27
    {
28 8
        return $this->count() > 0;
29
    }
30
31 19
    final public function jsonSerialize(): array
32
    {
33 19
        $values = [];
34 19
        foreach ($this->getItems() as $item) {
35 19
            $value = $item->jsonSerialize();
36 19
            if ($value) {
37 18
                $values[] = $value;
38
            }
39
        }
40
41 19
        return $values;
42
    }
43
}
44