Completed
Push — master ( 5b54fc...16c96d )
by Bertrand
14:42
created

ContextDto::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Agricultural\Dto;
5
6
7
use App\Src\UseCases\Domain\Agricultural\Model\PostalCode;
8
9
class ContextDto implements \JsonSerializable
10
{
11
    public $firstname;
12
    public $lastname;
13
    public $postalCode;
14
    public $department;
15
    public $characteristics;
16
    public $characteristicsByType;
17
18
    public function __construct(string $firstname, string $lastname, string $postalCode, array $characteristics = [])
19
    {
20
        $this->firstname = $firstname;
21
        $this->lastname = $lastname;
22
        $this->postalCode = $postalCode;
23
        $this->department = (new PostalCode($postalCode))->department();
24
        $this->characteristics = $characteristics;
25
        foreach($this->characteristics as $characteristic){
26
            $this->characteristicsByType[$characteristic->type()][] = $characteristic;
27
        }
28
    }
29
30
    public function jsonSerialize()
31
    {
32
        return [
33
            'firstname' => $this->firstname,
34
            'lastname' => $this->lastname,
35
            'postal_code' => $this->postalCode,
36
            'department' => $this->department,
37
            'productions' => $this->characteristicsByType[GetFarmingType::type] ?? [],
38
            'characteristics' => $this->characteristicsByType[GetFarmingType::typeSystem] ?? [],
39
        ];
40
    }
41
}
42