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

Codes::findByValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
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