Test Setup Failed
Push — master ( dcfdf2...6863da )
by guillaume
16:18 queued 10:15
created

Picture::relativePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Domain;
5
6
7
use App\Src\UseCases\Infra\Gateway\PictureHandler;
8
9
class Picture
10
{
11
    private $path;
12
    private $relativePath;
13
    private $ext;
14
15
    public function __construct(string $path, string $ext = null)
16
    {
17
        $this->path = $path;
18
        $this->ext = $ext;
19
    }
20
21
    public function resize(string $newPath)
22
    {
23
        $relativePath = $newPath;
24
        $finalNewPath = storage_path().'/'.$newPath;
25
        if(isset($this->ext)){
26
            $finalNewPath = storage_path().'/'.$newPath.'.'.$this->ext;
27
            $relativePath = $newPath.'.'.$this->ext;
28
        }
29
        if(app(PictureHandler::class)->width($this->path) > 600) {
30
            app(PictureHandler::class)->widen($this->path, $finalNewPath, 600);
31
            $this->relativePath = $relativePath;
32
            return;
33
        }
34
35
        if(app(PictureHandler::class)->height($this->path) > 400) {
36
            app(PictureHandler::class)->heighten($this->path, $finalNewPath, 400);
37
            $this->relativePath = $relativePath;
38
            return;
39
        }
40
41
        app(PictureHandler::class)->write($this->path, $finalNewPath);
42
        $this->relativePath = $relativePath;
43
    }
44
45
    public function relativePath(): string
46
    {
47
        return $this->relativePath;
48
    }
49
}
50