GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractDriver::getSourceImageResource()   A
last analyzed

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
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Image\Abstracts;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Image\File;
19
20
/**
21
 * Class AbstractDriver
22
 *
23
 * @package O2System\Image\Abstracts
24
 */
25
abstract class AbstractDriver
26
{
27
    /**
28
     * AbstractDriver::$imageProperties
29
     *
30
     * Library image file info.
31
     *
32
     * @var File
33
     */
34
    protected $sourceImageFile;
35
36
    /**
37
     * AbstractDriver::$imageResource
38
     *
39
     * Library image resource.
40
     *
41
     * @var resource|\Imagick|\Gmagick
42
     */
43
    protected $sourceImageResource;
44
45
    /**
46
     * AbstractDriver::$imageResample
47
     *
48
     * Library image resample resource.
49
     *
50
     * @var resource|\Imagick|\Gmagick
51
     */
52
    protected $resampleImageResource;
53
54
    /**
55
     * AbstractDriver::$imageResampleProperties
56
     *
57
     * Library image resample resource.
58
     *
59
     * @var File
60
     */
61
    protected $resampleImageFile;
62
63
    /**
64
     * AbstractDriver::$errors
65
     *
66
     * Library errors list.
67
     *
68
     * @var array
69
     */
70
    protected $errors = [];
71
72
    // ------------------------------------------------------------------------
73
74
    /**
75
     * AbstractDriver::setSourceImage
76
     *
77
     * Sets image source file path.
78
     *
79
     * @param string $imageFilePath Image source file path.
80
     *
81
     * @return bool
82
     */
83
    public function setSourceImage($imageFilePath)
84
    {
85
        if (is_file($imageFilePath)) {
86
            $this->sourceImageFile = new File($imageFilePath);
87
            $this->resampleImageFile = $this->sourceImageFile;
88
89
            return true;
90
        }
91
92
        return false;
93
    }
94
95
    // ------------------------------------------------------------------------
96
97
    /**
98
     * AbstractDriver::setResampleImage
99
     *
100
     * Sets resample image file.
101
     *
102
     * @param File $resampleFile Resample image file object.
103
     *
104
     * @return static
105
     */
106
    public function setResampleImage(File $resampleFile)
107
    {
108
        $this->resampleImageFile = $resampleFile;
109
110
        return $this;
111
    }
112
113
    // ------------------------------------------------------------------------
114
115
    /**
116
     * AbstractDriver::getSourceImageFile
117
     *
118
     * Gets image resource file object.
119
     *
120
     * @return \O2System\Image\File
121
     */
122
    public function getSourceImageFile()
123
    {
124
        return $this->sourceImageFile;
125
    }
126
127
    // ------------------------------------------------------------------------
128
129
    /**
130
     * AbstractDriver::getResampleImageFile
131
     *
132
     * Gets image resample file object.
133
     *
134
     * @return \O2System\Image\File
135
     */
136
    public function getResampleImageFile()
137
    {
138
        return $this->resampleImageFile;
139
    }
140
141
    // ------------------------------------------------------------------------
142
143
    /**
144
     * AbstractDriver::hasErrors
145
     *
146
     * Gets library image errors.
147
     *
148
     * @return bool
149
     */
150
    public function hasErrors()
151
    {
152
        if (count($this->errors)) {
153
            return true;
154
        }
155
156
        return false;
157
    }
158
159
    // ------------------------------------------------------------------------
160
161
    /**
162
     * AbstractDriver::getErrors
163
     *
164
     * Gets library image errors.
165
     *
166
     * @return array
167
     */
168
    public function getErrors()
169
    {
170
        return $this->errors;
171
    }
172
173
    // ------------------------------------------------------------------------
174
175
    /**
176
     * AbstractDriver::getTotalErrors
177
     *
178
     * Gets library image errors.
179
     *
180
     * @return bool
181
     */
182
    public function getTotalErrors()
183
    {
184
        return count($this->errors);
0 ignored issues
show
Bug Best Practice introduced by
The expression return count($this->errors) returns the type integer which is incompatible with the documented return type boolean.
Loading history...
185
    }
186
187
    // ------------------------------------------------------------------------
188
189
    /**
190
     * AbstractDriver::getMimeExtension
191
     *
192
     * Gets image mime extension.
193
     *
194
     * @param string $mime
195
     *
196
     * @return bool|string
197
     */
198
    public function getMimeExtension($mime)
199
    {
200
        $extensions = [
201
            'image/gif'  => 'gif',
202
            'image/jpg'  => 'jpg',
203
            'image/jpeg' => 'jpeg',
204
            'image/png'  => 'png',
205
            'image/webp' => 'webp',
206
        ];
207
208
        if (array_key_exists($mime, $extensions)) {
209
            return $extensions[ $mime ];
210
        }
211
212
        return false;
213
    }
214
215
    // ------------------------------------------------------------------------
216
217
    /**
218
     * AbstractDriver::createFromSource
219
     *
220
     * Create an image resource from source file.
221
     *
222
     * @return static
223
     */
224
    abstract public function createFromSource();
225
226
    // ------------------------------------------------------------------------
227
228
    /**
229
     * AbstractDriver::createFromString
230
     *
231
     * Create an image resource from image string.
232
     *
233
     * @param string $imageString Image string.
234
     *
235
     * @return void
236
     */
237
    abstract public function createFromString($imageString);
238
239
    /**
240
     * AbstractDriver::rotate
241
     *
242
     * Rotate an image with a given angle.
243
     *
244
     * @param float $degrees Image rotation degrees.
245
     *
246
     * @return void
247
     */
248
    abstract public function rotate($degrees);
249
250
    // ------------------------------------------------------------------------
251
252
    /**
253
     * AbstractDriver::resize
254
     *
255
     * Resize an image using the given new width and height.
256
     *
257
     * @return bool
258
     */
259
    abstract public function resize();
260
261
    // ------------------------------------------------------------------------
262
263
    /**
264
     * AbstractDriver::scale
265
     *
266
     * Scale an image with a given scale.
267
     *
268
     * @return bool
269
     */
270
    abstract public function scale();
271
272
    // ------------------------------------------------------------------------
273
274
    /**
275
     * AbstractDriver::flip
276
     *
277
     * Flip an image with a given axis.
278
     *
279
     * @param int $axis Flip axis.
280
     *
281
     * @return void
282
     */
283
    abstract public function flip($axis);
284
285
    // ------------------------------------------------------------------------
286
287
    /**
288
     * AbstractDriver::display
289
     *
290
     * Display an image.
291
     *
292
     * @return void
293
     */
294
    abstract public function display($quality = 100, $mime = null);
295
296
    // ------------------------------------------------------------------------
297
298
    /**
299
     * AbstractDriver::blob
300
     *
301
     * Return an image as blob string.
302
     *
303
     * @return string
304
     */
305
    abstract public function blob($quality = 100, $mime = null);
306
307
    // ------------------------------------------------------------------------
308
309
    /**
310
     * AbstractDriver::save
311
     *
312
     * Save an image.
313
     *
314
     * @param string $imageTargetFilePath
315
     * @param int    $quality
316
     *
317
     * @return bool
318
     */
319
    abstract public function save($imageTargetFilePath, $quality = 100);
320
321
    // ------------------------------------------------------------------------
322
323
    /**
324
     * AbstractDriver::getImageResource
325
     *
326
     * Gets library image resource.
327
     *
328
     * @return resource
329
     */
330
    protected function &getSourceImageResource()
331
    {
332
        return $this->sourceImageResource;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->sourceImageResource also could return the type Gmagick|Imagick which is incompatible with the documented return type resource.
Loading history...
333
    }
334
335
    // ------------------------------------------------------------------------
336
337
    /**
338
     * AbstractDriver::getImageOnProcess
339
     *
340
     * Gets library image on process resource.
341
     *
342
     * @return resource
343
     */
344
    protected function &getResampleImageResource()
345
    {
346
        if ( ! is_resource($this->resampleImageResource)) {
347
            $this->resampleImageResource = $this->sourceImageResource;
348
        }
349
350
        return $this->resampleImageResource;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->resampleImageResource also could return the type Gmagick|Imagick which is incompatible with the documented return type resource.
Loading history...
351
    }
352
}