Completed
Push — master ( 5b54fc...16c96d )
by Bertrand
14:42
created

Picture   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

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