ServicesResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 32
ccs 7
cts 7
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 3 1
A filterByServiceCode() 0 4 1
A getIterator() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DalliSDK\Responses;
6
7
use DalliSDK\Models\Price;
8
use DalliSDK\Models\Service;
9
use JMS\Serializer\Annotation as JMS;
10
11
/**
12
 * Сюда мапится ответ на запрос получения типов доставки
13
 *
14
 * @see https://api.dalli-service.com/v1/doc/request-types-of-delivery
15
 * @JMS\XmlRoot("services")
16
 *
17
 * @template-implements \IteratorAggregate<int, Service>
18
 */
19
class ServicesResponse implements ResponseInterface, \IteratorAggregate
20
{
21
    /**
22
     * @JMS\Type("array<DalliSDK\Models\Service>")
23
     * @JMS\XmlList(inline = true, entry = "service")
24
     * @var Service[]
25
     */
26
    private array $items = [];
27
28
    /**
29
     * @return \Traversable|Service[]
30
     */
31 1
    public function getIterator(): \ArrayIterator
32
    {
33 1
        return new \ArrayIterator($this->getItems());
34
    }
35
36
    /**
37
     * @return Service[]
38
     */
39 2
    public function getItems(): array
40
    {
41 2
        return $this->items;
42
    }
43
44
    /**
45
     * @return Service|bool
46
     */
47 1
    public function filterByServiceCode(int $code)
48
    {
49 1
        return current(array_filter($this->getItems(), function ($item) use ($code) {
50 1
            return $item->getCode() == $code;
51 1
        }));
52
    }
53
}
54