Collection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
getItems() 0 1 ?
A getIterator() 0 4 1
A hasItems() 0 4 1
A jsonSerialize() 0 12 3
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