Passed
Push — master ( 956624...05ed8c )
by Bertrand
08:49
created

Characteristic::pageId()   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 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Context\Model;
5
6
7
use App\Src\UseCases\Domain\Ports\CharacteristicsRepository;
8
use App\Src\UseCases\Domain\Shared\Model\HasMemento;
9
use App\Src\UseCases\Domain\Shared\Model\Memento;
10
11
class Characteristic implements HasMemento
12
{
13
    const FARMING_TYPE = 'farming';
14
    const CROPPING_SYSTEM = 'croppingSystem';
15
    const DEPARTMENT = 'department';
16
17
    private $title;
18
    private $type;
19
    private $visible;
20
    private $id;
21
    private $pageId;
22
    private $icon = null;
23
24
    public function __construct(string $id, string $type, string $title, bool $visible, int $pageId = null)
25
    {
26
        $this->id = $id;
27
        $this->pageId = $pageId;
28
        $this->type = $type;
29
        $this->title = $title;
30
        $this->visible = $visible;
31
    }
32
33
    public function create(string $icon = null)
34
    {
35
        if(isset($icon)){
36
            copy(storage_path('app/'.$icon), storage_path('app/public/characteristics/'.$this->id.'.png'));
37
            $this->icon = 'public/characteristics/'.$this->id.'.png';
38
        }
39
        app(CharacteristicsRepository::class)->save($this);
40
    }
41
42
    public function memento(): Memento
43
    {
44
        return new CharacteristicMemento($this->id, $this->type, $this->title, $this->visible, $this->icon, $this->pageId);
45
    }
46
47
    public function id(): string
48
    {
49
        return $this->id;
50
    }
51
52
    public function pageId(): ?int
53
    {
54
        return $this->pageId;
55
    }
56
}
57