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

ImageManipulator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 15
c 2
b 1
f 1
dl 0
loc 62
ccs 10
cts 20
cp 0.5
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriver() 0 7 2
A requirementsAreInstalled() 0 3 1
A supportedMimeTypes() 0 3 1
A supportedExtensions() 0 3 1
A newDriver() 0 3 1
A performConversion() 0 10 1
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