Passed
Push — master ( f60239...5cbdf1 )
by ihomyak
04:32
created

PickupPointList::getCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\Dto;
6
7
use JMS\Serializer\Annotation\Type;
8
9
/**
10
 * Class PickupPointList
11
 * @package CdekSDK2\Dto
12
 */
13
class PickupPointList
14
{
15
    /**
16
     * Список ПВЗ
17
     * @Type("array<CdekSDK2\Dto\PickupPoint>")
18
     * @var PickupPoint[]
19
     */
20
    public $items = [];
21
22
    /**
23
     * @return int
24
     */
25 1
    public function getCount(): int
26
    {
27 1
        return count($this->items);
28
    }
29
30
    /**
31
     * @param array $filter
32
     * @return array
33
     */
34 1
    public function filter(array $filter = []): array
35
    {
36 1
        $filtered = [];
37 1
        foreach ($this->items as $pvz) {
38 1
            foreach ($filter as $k => $v) {
39 1
                if (property_exists(PickupPoint::class, $k) && mb_strtolower($pvz->$k) === mb_strtolower($v)) {
40 1
                    $filtered[] = $pvz;
41 1
                    break;
42
                }
43
            }
44
        }
45 1
        return $filtered;
46
    }
47
}
48