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

ContextDto   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 9 1
A __construct() 0 9 2
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