Magickly   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 55
loc 55
ccs 16
cts 19
cp 0.8421
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 3
A getVersion() 11 11 2
A open() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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