Magickly::getVersion()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2
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\Exception\RuntimeException;
11
use GravityMedia\Magickly\MagicklyInterface;
12
13
/**
14
 * The Magickly class.
15
 *
16
 * @package GravityMedia\Magickly\Gmagick
17
 */
18 View Code Duplication
class Magickly implements MagicklyInterface
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    /**
21
     * @var string
22
     */
23
    private static $version;
24
25
    /**
26
     * Create Magickly object.
27
     *
28
     * @throws RuntimeException
29
     */
30 4
    public function __construct()
31
    {
32 4
        if (!class_exists('Gmagick')) {
33
            throw new RuntimeException('Gmagick not installed');
34
        }
35
36 4
        $version = $this->getVersion();
37 4
        if (version_compare('1.3.0', $version) > 0) {
38
            throw new RuntimeException(sprintf('ImageMagick version 1.3.0 or higher is required, %s provided', $version));
39
        }
40 4
    }
41
42
    /**
43
     * Get version.
44
     *
45
     * @return string
46
     */
47 4
    public function getVersion()
48
    {
49 4
        if (null === self::$version) {
50 2
            $gmagick = new \Gmagick();
51 2
            $version = $gmagick->getVersion();
52
53 2
            list(self::$version) = sscanf($version['versionString'], 'GraphicsMagick %s %04d-%02d-%02d %s %s');
54 1
        }
55
56 4
        return self::$version;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function open($path)
63
    {
64
        try {
65 2
            $gmagick = new \Gmagick($path);
66 1
        } 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...
67
            throw new RuntimeException(sprintf('Unable to open image %s', $path), 0, $exception);
68
        }
69
70 2
        return new Image($gmagick);
71
    }
72
}
73