FindOfficeResponse::getOffices()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.1852

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 1
cts 3
cp 0.3333
crap 3.1852
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Speedy\Service\Location\Office;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use JMS\Serializer\Annotation as Serializer;
9
use VasilDakov\Speedy\Model\Office;
10
11
/**
12
 * Class FindOfficeResponse.
13
 *
14
 * @author Vasil Dakov <[email protected]>
15
 * @copyright 2009-2022 Neutrino.bg
16
 *
17
 * @version 1.0
18
 *
19
 * @Serializer\AccessType("public_method")
20
 */
21
class FindOfficeResponse
22
{
23
    /**
24
     * @Serializer\Type("ArrayCollection<VasilDakov\Speedy\Model\Office>")
25
     */
26
    public ArrayCollection $offices;
27 1
28
    public function __construct()
29 1
    {
30
        $this->offices = new ArrayCollection();
31
    }
32 1
33
    public function getOffices(?string $type = null): ArrayCollection
34 1
    {
35
        if (!$type) {
36
            return $this->offices;
37
        }
38
39
        return $this->offices->filter(function (Office $office) use ($type) {
40
            return $office->getType() == $type;
41
        });
42
    }
43
44
    public function setOffices(ArrayCollection $offices): void
45
    {
46
        $this->offices = $offices;
47
    }
48
}
49