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

Picture   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A relativePath() 0 3 1
A __construct() 0 4 1
A resize() 0 22 4
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