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

Characteristic   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 7 2
A pageId() 0 3 1
A id() 0 3 1
A __construct() 0 7 1
A memento() 0 3 1
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