PickupPointList::getCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
    public function getCount(): int
26
    {
27
        return count($this->items);
28
    }
29
30
    /**
31
     * @param array $filter
32
     * @return array
33
     */
34
    public function filter(array $filter = []): array
35
    {
36
        $filtered = [];
37
        foreach ($this->items as $pvz) {
38
            foreach ($filter as $k => $v) {
39
                if (property_exists(PickupPoint::class, $k) && mb_strtolower($pvz->$k) === mb_strtolower($v)) {
40
                    $filtered[] = $pvz;
41
                    break;
42
                }
43
            }
44
        }
45
        return $filtered;
46
    }
47
}
48