Completed
Push — master ( 1316ca...59eabb )
by Daniel
11:50
created

Image::getColorSpace()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 14
loc 14
rs 8.8571
cc 5
eloc 11
nc 5
nop 0
1
<?php
2
/**
3
 * This file is part of the Magickly project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Magickly\Gmagick;
9
10
use GravityMedia\Magickly\Enum\ColorSpace;
11
use GravityMedia\Magickly\Exception\RuntimeException;
12
use GravityMedia\Magickly\Image\AbstractImage;
13
use GravityMedia\Magickly\Image\ColorProfile;
14
15
/**
16
 * The image class.
17
 *
18
 * @package GravityMedia\Magickly\Gmagick
19
 */
20
class Image extends AbstractImage
21
{
22
    /**
23
     * @var \Gmagick
24
     */
25
    protected $gmagick;
26
27
    /**
28
     * @var array
29
     */
30
    protected static $colorspaceMapping = [
31
        ColorSpace::COLOR_SPACE_RGB => \Gmagick::COLORSPACE_RGB,
32
        ColorSpace::COLOR_SPACE_CMYK => \Gmagick::COLORSPACE_CMYK,
33
        ColorSpace::COLOR_SPACE_GRAYSCALE => \Gmagick::COLORSPACE_GRAY
34
    ];
35
36
    /**
37
     * Create image object.
38
     *
39
     * @param \Gmagick $gmagick
40
     */
41
    public function __construct(\Gmagick $gmagick)
42
    {
43
        $this->gmagick = $gmagick;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 View Code Duplication
    public function getColorSpace()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        switch ($this->gmagick->getimagecolorspace()) {
52
            case \Gmagick::COLORSPACE_RGB:
53
            case \Gmagick::COLORSPACE_SRGB:
54
                return ColorSpace::COLOR_SPACE_RGB;
55
            case \Gmagick::COLORSPACE_CMYK:
56
                return ColorSpace::COLOR_SPACE_CMYK;
57
            case \Gmagick::COLORSPACE_GRAY:
58
                return ColorSpace::COLOR_SPACE_GRAYSCALE;
59
            default:
60
                throw new RuntimeException('Only RGB, grayscale and CMYK colorspace are currently supported');
61
        }
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 View Code Duplication
    public function setColorSpace($colorspace)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        if (!isset(static::$colorspaceMapping[$colorspace])) {
70
            throw new RuntimeException('Only RGB, grayscale and CMYK colorspace are currently supported');
71
        }
72
73
        $this->gmagick->setimagecolorspace(static::$colorspaceMapping[$colorspace]);
74
75
        return $this;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getColorProfile()
82
    {
83
        try {
84
            $data = $this->gmagick->getimageprofile('ICM');
85
        } catch (\GmagickException $exception) {
0 ignored issues
show
Bug introduced by
The class GmagickException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
86
            return null;
87
        }
88
89
        return new ColorProfile($data);
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function setColorProfile(ColorProfile $colorProfile)
96
    {
97
        $this->gmagick->setimageprofile('ICM', $colorProfile->getData());
98
99
        return $this;
100
    }
101
}
102