Map::getItems()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 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 Map implements Definition, Countable, IteratorAggregate
13
{
14 15
    final public function count(): int
15
    {
16 15
        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 14
    final public function hasItems(): bool
27
    {
28 14
        return $this->count() > 0;
29
    }
30
31 55
    public function jsonSerialize(): ?array
32
    {
33 55
        $values = [];
34 55
        foreach ($this->getItems() as $key => $item) {
35 48
            $value = $item->jsonSerialize();
36 48
            if ($value) {
37 47
                $values[$key] = $value;
38
            }
39
        }
40
41 55
        if (empty($values)) {
42 11
            return null;
43
        }
44
45 47
        return $values;
46
    }
47
}
48