ItemsResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addItem() 0 3 1
A toArray() 0 3 1
A createEmpty() 0 3 1
A all() 0 4 2
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusElasticsearchPlugin\Controller\Response;
12
13
use BitBag\SyliusElasticsearchPlugin\Controller\Response\DTO\Item;
14
15
final class ItemsResponse
16
{
17
    /** @var array|Item[] */
18
    private $items;
19
20
    private function __construct(array $itemsList)
21
    {
22
        $this->items = $itemsList;
23
    }
24
25
    public static function createEmpty(): self
26
    {
27
        return new self([]);
28
    }
29
30
    public function addItem(DTO\Item $item): void
31
    {
32
        $this->items[] = $item;
33
    }
34
35
    public function all(): \Traversable
36
    {
37
        foreach ($this->items as $item) {
38
            yield $item->toArray();
39
        }
40
    }
41
42
    public function toArray(): array
43
    {
44
        return ['items' => iterator_to_array($this->all())];
45
    }
46
}
47