Passed
Push — master ( 1fa5c8...3c4917 )
by Gabriel
02:55
created

Codes::serializeElements()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 2
nop 1
crap 5
1
<?php
2
3
namespace Waredesk\Collections\Products\Variants;
4
5
use Waredesk\Collection;
6
use Waredesk\Models\Product\Variant\Code;
7
use JsonSerializable;
8
9
/**
10
 * @method Code first()
11
 * @method Code current()
12
 * @method Code next()
13
 * @method Code offsetGet($offset)
14
 */
15
class Codes extends Collection
16
{
17
    /**
18
     * @param Code $item
19
     */
20
    public function add($item): void
21
    {
22
        parent::add($item);
23
    }
24
25
    public function findByValue(string $value): ? Code
26
    {
27
        /** @var Code $item */
28
        foreach ($this->items as $item) {
29
            if ($item->getValue() === $value) {
30
                return $item;
31
            }
32
        }
33
        return null;
34
    }
35
36
    public function findByType(string $type): ? Code
37
    {
38
        /** @var Code $item */
39
        foreach ($this->items as $item) {
40
            if ($item->getType() === $type || $item->getCustomType() === $type) {
41
                return $item;
42
            }
43
        }
44
        return null;
45
    }
46
}
47