Thumb::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace WagnerMontanini\GoomerApi\Support;
4
5
use CoffeeCode\Cropper\Cropper;
6
7
/**
8
 * Class Thumb
9
 *
10
 * @author Wagner Montanini
11
 * @package WagnerMontanini\GoomerApi\Support
12
 */
13
class Thumb
14
{
15
    /** @var Cropper */
16
    private $cropper;
17
18
    /** @var string */
19
    private $uploads;
20
21
    /**
22
     * Thumb constructor.
23
     */
24
    public function __construct()
25
    {
26
        $this->cropper = new Cropper(CONF_IMAGE_CACHE, CONF_IMAGE_QUALITY['jpg'], CONF_IMAGE_QUALITY['png']);
27
        $this->uploads = CONF_UPLOAD_DIR;
28
    }
29
30
    /**
31
     * @param string $image
32
     * @param int $width
33
     * @param int|null $height
34
     * @return string
35
     */
36
    public function make(string $image, int $width, ?int $height = null): string
37
    {
38
        return $this->cropper->make("{$this->uploads}/{$image}", $width, $height);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->cropper->m...image, $width, $height) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
39
    }
40
41
    /**
42
     * @param string|null $image
43
     */
44
    public function flush(?string $image = null): void
45
    {
46
        if ($image) {
47
            $this->cropper->flush("{$this->uploads}/{$image}");
48
            return;
49
        }
50
51
        $this->cropper->flush();
52
        return;
53
    }
54
55
    /**
56
     * @return Cropper
57
     */
58
    public function cropper(): Cropper
59
    {
60
        return $this->cropper;
61
    }
62
}