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

Page   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A pageId() 0 3 1
A toArray() 0 4 1
A setOnDryState() 0 4 1
A createCharacteristicAssociated() 0 12 2
A __construct() 0 13 1
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Context\Model;
5
6
7
use App\Src\UseCases\Domain\Ports\PageRepository;
8
use Ramsey\Uuid\Uuid;
9
10
class Page
11
{
12
    private $pageId;
13
    private $dryState;
14
    private $title;
15
    private $type;
16
    private $icon;
17
18
    const TYPE_CULTURE = 'Culture';
19
20
    public function __construct(
21
        int $pageId,
22
        bool $dryState = false,
23
        string $title = null,
24
        string $type = null,
25
        string $icon = null
26
    )
27
    {
28
        $this->pageId = $pageId;
29
        $this->dryState = $dryState;
30
        $this->title = $title;
31
        $this->type = $type;
32
        $this->icon = $icon;
33
    }
34
35
    public function pageId():int
36
    {
37
        return $this->pageId;
38
    }
39
40
    public function setOnDryState()
41
    {
42
        $this->dryState = true;
43
        app(PageRepository::class)->save($this);
44
    }
45
46
    public function createCharacteristicAssociated():Characteristic
47
    {
48
        $type = $this->type === self::TYPE_CULTURE ? Characteristic::FARMING_TYPE : Characteristic::CROPPING_SYSTEM;
49
        $characteristic = new Characteristic(
50
            Uuid::uuid4(),
51
            $type,
52
            $this->title,
0 ignored issues
show
Bug introduced by
It seems like $this->title can also be of type null; however, parameter $title of App\Src\UseCases\Domain\...teristic::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
            /** @scrutinizer ignore-type */ $this->title,
Loading history...
53
            false,
54
            $this->pageId
55
        );
56
        $characteristic->create($this->icon);
57
        return $characteristic;
58
    }
59
60
    public function toArray()
61
    {
62
        return [
63
            'dry' => $this->dryState
64
        ];
65
    }
66
}
67