Organization   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 11 2
A name() 0 3 1
A __construct() 0 6 1
A toArray() 0 9 2
A id() 0 3 1
A create() 0 9 2
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Organizations\Model;
5
6
7
use App\Src\UseCases\Domain\Ports\OrganizationRepository;
8
use App\Src\UseCases\Domain\Shared\Model\Picture;
9
10
class Organization
11
{
12
    private $id;
13
    private $name;
14
    private $pathPicture;
15
    private $address;
16
17
    public function __construct(string $id, string $name, string $pathPicture, Address $address)
18
    {
19
        $this->id = $id;
20
        $this->name = $name;
21
        $this->pathPicture = $pathPicture;
22
        $this->address = $address;
23
    }
24
25
    public function id():string
26
    {
27
        return $this->id;
28
    }
29
30
    public function name():string
31
    {
32
        return $this->name;
33
    }
34
35
    public function create(string $ext = 'jpg')
36
    {
37
        if($this->pathPicture !== "") {
38
            $picture = new Picture($this->pathPicture);
39
            $picture->resize('app/public/organizations/' . $this->id . '.' . $ext);
40
            $this->pathPicture = 'app/public/organizations/' . $this->id . '.' . $ext;
41
        }
42
43
        app(OrganizationRepository::class)->add($this);
44
    }
45
46
    public function update(string $name, array $picture, Address $address)
47
    {
48
        $this->name = $name;
49
        $this->address = $address;
50
        if($picture['path'] !== "") {
51
            $logo = new Picture($picture['path']);
52
            $ext = $picture['ext'];
53
            $logo->resize('app/public/organizations/' . $this->id . '.' . $ext);
54
            $this->pathPicture = 'app/public/organizations/' . $this->id . '.' . $ext;
55
        }
56
        app(OrganizationRepository::class)->update($this);
57
    }
58
59
    public function toArray()
60
    {
61
        $urlPicture = $this->pathPicture != "" ? asset('storage/'.str_replace('app/public/', '', $this->pathPicture)) : null;
62
        return array_merge([
63
            'uuid' => $this->id,
64
            'name' => $this->name,
65
            'path_picture' => $this->pathPicture,
66
            'url_picture' => $urlPicture,
67
        ], $this->address->toArray());
68
    }
69
}
70