Completed
Push — master ( 0ca8d8...94fc1e )
by Daniel
12:22
created

Magickly::getVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 11
loc 11
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
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\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
    public function __construct()
31
    {
32
        if (!class_exists('Gmagick')) {
33
            throw new RuntimeException('Gmagick not installed');
34
        }
35
36
        $version = $this->getVersion();
37
        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
    }
41
42
    /**
43
     * Get version.
44
     *
45
     * @return string
46
     */
47
    public function getVersion()
48
    {
49
        if (null === self::$version) {
50
            $gmagick = new \Gmagick();
51
            $version = $gmagick->getVersion();
52
53
            list(self::$version) = sscanf($version['versionString'], 'GraphicsMagick %s %04d-%02d-%02d %s %s');
54
        }
55
56
        return self::$version;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function open($path)
63
    {
64
        $gmagick = new \Gmagick($path);
65
66
        return new Image($gmagick);
67
    }
68
}
69