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.

Optimizer::optimize()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 4
nop 1
dl 0
loc 9
rs 9.6111
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;
15
16
// ------------------------------------------------------------------------
17
18
use ImageOptimizer\OptimizerFactory;
19
use O2System\Image\Optimizers\Imageoptim;
20
use O2System\Image\Optimizers\Optimus;
21
22
/**
23
 * Class Optimizer
24
 * @package O2System\Image
25
 */
26
class Optimizer
27
{
28
    /**
29
     * Optimizer::$imageFactory
30
     *
31
     * @var Imageoptim|Optimus
32
     */
33
    protected $imageFactory = null;
34
35
    // ------------------------------------------------------------------------
36
37
    /**
38
     * Optimizer::setImageFactory
39
     *
40
     * @param $imageFactory
41
     *
42
     * @return static
43
     */
44
    public function setImageFactory($imageFactory)
45
    {
46
        if ($imageFactory instanceof Imageoptim || $imageFactory instanceof Optimus) {
47
            $this->imageFactory = $imageFactory;
48
        }
49
50
        return $this;
51
    }
52
53
    // ------------------------------------------------------------------------
54
55
    /**
56
     * Optimizer::optimize
57
     *
58
     * @param string $imageFilePath
59
     *
60
     * @throws \Exception
61
     */
62
    public function optimize($imageFilePath)
63
    {
64
        if (empty($this->imageFactory)) {
65
            if (class_exists('\ImageOptimizer\OptimizerFactory')) {
66
                (new OptimizerFactory())->get()->optimize($imageFilePath);
67
            }
68
        } elseif ($this->imageFactory instanceof Imageoptim || $this->imageFactory instanceof Optimus) {
0 ignored issues
show
introduced by
$this->imageFactory is always a sub-type of O2System\Image\Optimizers\Optimus.
Loading history...
69
            $imageString = $this->imageFactory->optimize($imageFilePath, 'full');
70
            file_put_contents($imageFilePath, $imageString);
71
        }
72
    }
73
}