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.
Completed
Push — master ( 037104...b3593d )
by
unknown
10s
created

ImageService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 1
eloc 9
nc 1
nop 4
crap 1
1
<?php
2
namespace HtImgModule\Service;
3
4
use Imagine\Image\ImagineInterface;
5
use HtImgModule\Imagine\Filter\FilterManagerInterface;
6
use HtImgModule\Imagine\Loader\LoaderManagerInterface;
7
use HtImgModule\EventManager\EventProvider;
8
9
class ImageService extends EventProvider implements ImageServiceInterface
10
{
11
    /**
12
     * @var CacheManagerInterface
13
     */
14
    protected $cacheManager;
15
16
    /**
17
     * @var ImagineInterface
18
     */
19
    protected $imagine;
20
21
    /**
22
     * @var FilterManagerInterface
23
     */
24
    protected $filterManager;
25
26
    /**
27
     * @var LoaderManagerInterface
28
     */
29
    protected $loaderManager;
30
31
    /**
32
     * Constructor
33
     *
34
     * @param CacheManagerInterface  $cacheManager
35
     * @param ImagineInterface       $imagine
36
     * @param FilterManagerInterface $filterManager
37
     * @param LoaderManagerInterface $loaderManager
38
     */
39 3
    public function __construct(
40
        CacheManagerInterface  $cacheManager,
41
        ImagineInterface $imagine,
42
        FilterManagerInterface $filterManager,
43
        LoaderManagerInterface $loaderManager
44
    ) {
45 3
        $this->cacheManager  = $cacheManager;
46 3
        $this->imagine       = $imagine;
47 3
        $this->filterManager = $filterManager;
48 3
        $this->loaderManager = $loaderManager;
49 3
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 2
    public function getImage($relativePath, $filter)
55
    {
56 2
        $eventManager = $this->getEventManager();
57 2
        $eventManager->trigger(__FUNCTION__, $this, ['relativePath' => $relativePath, 'filter' => $filter]);
58
59 2
        $filterOptions = $this->filterManager->getFilterOptions($filter);
60
61 2
        $binary = $this->loaderManager->loadBinary($relativePath, $filter);
62
63 2
        if (isset($filterOptions['format'])) {
64 1
            $format = $filterOptions['format'];
65
        } else {
66 1
            $format = $binary->getFormat() ?: 'png';
67
        }
68
69 2
        $imageOutputOptions = [];
70 2
        if (isset($filterOptions['quality'])) {
71 2
            $imageOutputOptions['quality'] = $filterOptions['quality'];
72
        }
73 2
        if ($format === 'gif' && $filterOptions['animated']) {
74 1
            $imageOutputOptions['animated'] = $filterOptions['animated'];
75
        }
76
77 2
        if ($this->cacheManager->isCachingEnabled($filter, $filterOptions) && $this->cacheManager->cacheExists($relativePath, $filter, $format)) {
78 1
            $imagePath      = $this->cacheManager->getCachePath($relativePath, $filter, $format);
79 1
            $filteredImage  = $this->imagine->open($imagePath);
80
        } else {
81 1
            $image          = $this->imagine->load($binary->getContent());
82 1
            $filteredImage  = $this->filterManager->getFilter($filter)->apply($image);
83
84 1
            if ($this->cacheManager->isCachingEnabled($filter, $filterOptions)) {
85 1
                $this->cacheManager->createCache($relativePath, $filter, $filteredImage, $format, $imageOutputOptions);
86
            }
87
        }
88
89 2
        $args = ['relativePath' => $relativePath, 'filter' => $filter, 'filteredImage' => $filteredImage, 'format' => $format];
90 2
        $eventManager->trigger(__FUNCTION__.'.post', $this, $args);
91
92
        return [
93 2
            'image'  => $filteredImage,
94 2
            'format' => $format,
95 2
            'imageOutputOptions' => $imageOutputOptions,
96
        ];
97
    }
98
}
99