Resource::setWidth()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Erykai\Compress;
4
5
/**
6
 *
7
 */
8
abstract class Resource
9
{
10
    use TraitCompress;
11
12
    /**
13
     * @var string
14
     */
15
    protected string $path;
16
    /**
17
     * @var string
18
     */
19
    protected string $file;
20
    /**
21
     * @var int
22
     */
23
    protected int $quality;
24
    /**
25
     * @var int
26
     */
27
    protected int $width;
28
    /**
29
     * @var string
30
     */
31
    protected string $input;
32
    /**
33
     * @var string
34
     */
35
    protected string $output;
36
37
    /**
38
     * @param string $path
39
     * @param string $file
40
     * @param int $quality
41
     * @param int $width
42
     */
43
    public function __construct(string $path, string $file, int $quality, int $width = 0)
44
    {
45
        $this->setPath($path);
46
        $this->setFile($file);
47
        $this->setQuality($quality);
48
        $this->setInput($this->getPath() ."/". $this->getFile());
49
        $this->setWidth($width);
50
        //create dir temp
51
        $pathOut = $this->getPath() . "/compress_temp";
52
        $this->createDir($pathOut);
53
        $this->setOutput($pathOut . "/" . $this->getFile());
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    protected function getPath(): string
60
    {
61
        return $this->path;
62
    }
63
64
    /**
65
     * @param string $path
66
     */
67
    protected function setPath(string $path): void
68
    {
69
        $this->path = $path;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    protected function getFile(): string
76
    {
77
        return $this->file;
78
    }
79
80
    /**
81
     * @param string $file
82
     */
83
    protected function setFile(string $file): void
84
    {
85
        $this->file = $file;
86
    }
87
88
    /**
89
     * @return int
90
     */
91
    protected function getQuality(): int
92
    {
93
        return $this->quality;
94
    }
95
96
    /**
97
     * @param int $quality
98
     */
99
    protected function setQuality(int $quality): void
100
    {
101
        $this->quality = $quality;
102
    }
103
104
    /**
105
     * @return int
106
     */
107
    protected function getWidth(): int
108
    {
109
        return $this->width;
110
    }
111
112
    /**
113
     * @param int $width
114
     */
115
    protected function setWidth(int $width): void
116
    {
117
        if(!$width)
118
        {
119
            [$width] = getimagesize($this->getInput());
120
            if($width > 1920){
121
                $width = 1920;
122
            }
123
        }
124
125
        $this->width = $width;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    protected function getInput(): string
132
    {
133
        return $this->input;
134
    }
135
136
    /**
137
     * @param string $input
138
     */
139
    protected function setInput(string $input): void
140
    {
141
        $this->input = $input;
142
    }
143
144
    /**
145
     * @return string
146
     */
147
    protected function getOutput(): string
148
    {
149
        return $this->output;
150
    }
151
152
    /**
153
     * @param string $output
154
     */
155
    protected function setOutput(string $output): void
156
    {
157
        $this->output = $output;
158
    }
159
160
161
}