Passed
Push — master ( 1ffd02...b93f0b )
by Bertrand
06:21
created

Context::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Agricultural\Model;
5
6
7
use App\Src\UseCases\Domain\Ports\ContextRepository;
8
9
class Context
10
{
11
    private $uid;
12
    private $postalCode;
13
    private $farmingType;
14
    private $contextRepository;
15
16
    public function __construct(string $id, string $postalCode, array $farmingType = [])
17
    {
18
        $this->uid = $id;
19
        $this->postalCode = $postalCode;
20
        $this->farmingType = $farmingType;
21
        $this->contextRepository = app(ContextRepository::class);
22
    }
23
24
    public function create(string $userId)
25
    {
26
        $this->contextRepository->add($this, $userId);
27
    }
28
29
    public function toArray()
30
    {
31
        return [
32
            'uuid' => $this->uid,
33
            'postal_code' => $this->postalCode,
34
            'farmings' => json_encode($this->farmingType),
35
        ];
36
    }
37
}
38