ContextDto   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 30 2
A fullname() 0 3 1
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Context\Dto;
5
6
7
use App\Src\UseCases\Domain\Context\Model\Characteristic;
8
use App\Src\UseCases\Domain\Shared\Model\Dto;
9
10
class ContextDto extends Dto
11
{
12
    public $firstname;
13
    public $lastname;
14
    public $postalCode;
15
    public $department;
16
    public $characteristics;
17
    public $productions;
18
    public $characteristicsDepartement;
19
    public $description;
20
    public $sector;
21
    public $structure;
22
    public $userUuid;
23
    public $fullname;
24
25
    public function __construct(
26
        string $firstname,
27
        string $lastname,
28
        string $postalCode,
29
        array $characteristics,
30
        ?string $description,
31
        ?string $sector,
32
        ?string $structure,
33
        ?string $userUuid = null,
34
        string $departmentNumber = null
35
    )
36
    {
37
        $this->firstname = $firstname;
38
        $this->lastname = $lastname;
39
        $this->postalCode = $postalCode;
40
        $this->department = $departmentNumber;
41
        $this->fullname = $this->fullname();
42
        $characteristicsByType = [];
43
        foreach($characteristics as $characteristic){
44
            $characteristicsByType[$characteristic->type()][] = $characteristic;
45
        }
46
47
        $this->characteristicsDepartement = $characteristicsByType[Characteristic::DEPARTMENT] ?? [];
48
        $this->characteristics = $characteristicsByType[Characteristic::CROPPING_SYSTEM] ?? [];
49
        $this->productions = $characteristicsByType[Characteristic::FARMING_TYPE] ?? [];
50
51
        $this->description = $description;
52
        $this->sector = $sector;
53
        $this->structure = $structure;
54
        $this->userUuid = $userUuid;
55
    }
56
57
    private function fullname():string
58
    {
59
        return $this->firstname.' '.$this->lastname;
60
    }
61
62
}
63