Passed
Push — master ( 0d0194...c6f9a3 )
by Gabriel
09:21 queued 06:24
created

ImageManipulator::performConversion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ByTIC\MediaLibrary\Media\Manipulators\Images;
4
5
use ByTIC\MediaLibrary\Conversions\Conversion;
6
use ByTIC\MediaLibrary\Media\Manipulators\AbstractManipulator;
7
use ByTIC\MediaLibrary\Media\Manipulators\Images\Drivers\AbstractDriver;
8
use ByTIC\MediaLibrary\Media\Manipulators\Images\Drivers\ImagineDriver;
9
use ByTIC\MediaLibrary\Media\Media;
10
use Nip\Collection;
11
12
/**
13
 * Class ImageManipulator.
14
 */
15
class ImageManipulator extends AbstractManipulator
16
{
17
    protected $driver = null;
18
19
    /**
20
     * @param Media      $media
21
     * @param Conversion $conversion
22
     */
23
    public function performConversion(Media $media, Conversion $conversion)
24
    {
25
        $imageContent = $this->getDriver()->manipulate(
26
            $media->getFile()->read(),
27
            $conversion->getManipulations(),
28
            $media->getExtension()
29
        );
30
31
        $path = $media->getPath($conversion->getName());
32
        $media->getCollection()->getFilesystem()->put($path, $imageContent);
33
    }
34
35
    /**
36
     * @return AbstractDriver
37
     */
38 1
    public function getDriver()
39
    {
40 1
        if ($this->driver === null) {
41 1
            $this->driver = $this->newDriver();
42
        }
43
44 1
        return $this->driver;
45
    }
46
47
    /**
48
     * @return ImagineDriver
49
     */
50 1
    protected function newDriver()
51
    {
52 1
        return new ImagineDriver();
53
    }
54
55
    /**
56
     * @return bool
57
     */
58 4
    public function requirementsAreInstalled(): bool
59
    {
60 4
        return true;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 4
    public function supportedExtensions(): Collection
67
    {
68 4
        return new Collection(['png', 'jpg', 'jpeg', 'gif']);
0 ignored issues
show
Deprecated Code introduced by
The class Nip\Collection has been deprecated: Use new Collection class from Nip/Collection repo ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
        return /** @scrutinizer ignore-deprecated */ new Collection(['png', 'jpg', 'jpeg', 'gif']);
Loading history...
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function supportedMimeTypes(): Collection
75
    {
76
        return new Collection(['image/jpeg', 'image/gif', 'image/png']);
0 ignored issues
show
Deprecated Code introduced by
The class Nip\Collection has been deprecated: Use new Collection class from Nip/Collection repo ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

76
        return /** @scrutinizer ignore-deprecated */ new Collection(['image/jpeg', 'image/gif', 'image/png']);
Loading history...
77
    }
78
}
79