ImageFactory   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 89.66%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 9
c 2
b 0
f 2
lcom 1
cbo 2
dl 0
loc 81
ccs 26
cts 29
cp 0.8966
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createNewImage() 0 4 1
A rebuildFilters() 0 19 3
A _hasFilter() 0 9 2
A _getFilterInstance() 0 18 3
1
<?php
2
3
/*
4
 * This file is part of the kaloa/image package.
5
 *
6
 * For full copyright and license information, please view the LICENSE file
7
 * that was distributed with this source code.
8
 */
9
10
namespace Kaloa\Image;
11
12
use Kaloa\Image\Filter\FilterInterface;
13
use ReflectionClass;
14
15
/**
16
 *
17
 */
18
final class ImageFactory
19
{
20
    /**
21
     *
22
     * @var array Array of FilterInterface
23
     */
24
    private $filters = null;
25
26
    /**
27
     *
28
     * @return Image
29
     */
30 6
    public function createNewImage()
31
    {
32 6
        return new Image($this);
33
    }
34
35
    /**
36
     *
37
     */
38 1
    private function rebuildFilters()
39
    {
40 1
        $files = glob(__DIR__ . '/Filter/*Filter.php');
41
42 1
        $this->filters = array();
43
44 1
        foreach ($files as $file) {
45 1
            $basename = basename($file);
46
47 1
            if ($basename === 'AbstractFilter.php') {
48 1
                continue;
49
            }
50
51 1
            $className = 'Kaloa\\Image\\Filter\\' . substr($basename, 0, -4);
52 1
            $methodName = lcfirst(substr($basename, 0, -10));
53
54 1
            $this->filters[$methodName] = $className;
55 1
        }
56 1
    }
57
58
    /**
59
     *
60
     * @param  string $methodName
61
     * @return bool
62
     */
63 1
    public function _hasFilter($methodName)
64
    {
65
        // Lazy loading
66 1
        if (null === $this->filters) {
67 1
            $this->rebuildFilters();
68 1
        }
69
70 1
        return (isset($this->filters[$methodName]));
71
    }
72
73
    /**
74
     *
75
     * @param  string $methodName
76
     * @param  array  $arguments
77
     * @return FilterInterface
78
     * @throws ImageException
79
     */
80 1
    public function _getFilterInstance($methodName, $arguments)
81
    {
82
        // Lazy loading
83 1
        if (null === $this->filters) {
84
            $this->rebuildFilters();
85
        }
86
87 1
        $instance = null;
0 ignored issues
show
Unused Code introduced by
$instance is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
88
89 1
        if (!$this->_hasFilter($methodName)) {
90
            throw new ImageException('Unknown filter: ' . $methodName);
91
        } else {
92 1
            $reflection = new ReflectionClass($this->filters[$methodName]);
93 1
            $instance = $reflection->newInstanceArgs($arguments);
94
        }
95
96 1
        return $instance;
97
    }
98
}
99