Test Failed
Push — main ( 33bb6d...d24563 )
by Vasil
03:10
created

GetCitiesResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Econt\Response;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use JMS\Serializer\Annotation as Serializer;
9
use VasilDakov\Econt\Model;
10
11
final class GetCitiesResponse
12
{
13
    #[Serializer\Type("ArrayCollection<VasilDakov\Econt\Model\City>")]
14
    private ArrayCollection $cities;
15
16
    public function __construct()
17
    {
18
        $this->cities = new ArrayCollection();
19
    }
20
21
    public function findById(int $id): ?Model\City
22
    {
23
        $collection = $this->cities->filter(function (Model\City $city) use ($id) {
24
            return $city->id === $id;
25
        });
26
27
        return (!$collection->isEmpty()) ? $collection->first() : null;
28
    }
29
30
    public function findByName(string $name): ?Model\City
31
    {
32
        $collection = $this->cities->filter(function (Model\City $city) use ($name) {
33
            return $city->name === $name;
34
        });
35
36
        return (!$collection->isEmpty()) ? $collection->first() : null;
37
    }
38
}
39