Completed
Push — master ( 160c43...fb9933 )
by Markus
05:54
created

ServiceStorage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 89.19%

Importance

Changes 10
Bugs 0 Features 2
Metric Value
wmc 10
c 10
b 0
f 2
lcom 1
cbo 3
dl 0
loc 94
ccs 33
cts 37
cp 0.8919
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getCallable() 0 4 1
A isCalledService() 0 4 2
A setObjectFactory() 0 4 1
A setObjectTransformer() 0 4 1
A reader() 0 10 1
A writer() 0 9 1
A info() 0 8 1
A getFields() 0 4 1
1
<?php
2
namespace Mathielen\ImportEngine\Storage;
3
4
use Mathielen\DataImport\Reader\ServiceReader;
5
use Mathielen\DataImport\Writer\ServiceWriter;
6
7
class ServiceStorage implements StorageInterface
8
{
9
10
    /**
11
     * @var callable
12
     */
13
    private $callable;
14
15
    /**
16
     * @var array
17
     */
18
    private $arguments;
19
20
    private $objectTransformer;
21
    private $objectFactory;
22
23 6
    public function __construct(callable $callable, $arguments = array(), $objectMapper = null)
24
    {
25 6
        $this->callable = $callable;
26 6
        $this->arguments = $arguments;
27 6
        $this->setObjectFactory($objectMapper);
28 6
        $this->setObjectTransformer($objectMapper);
29 6
    }
30
31
    /**
32
     * @return callable
33
     */
34
    public function getCallable()
35
    {
36
        return $this->callable;
37
    }
38
39 2
    public function isCalledService($serviceOrClassname)
40
    {
41 2
        return is_a($this->callable[0], is_object($serviceOrClassname) ? get_class($serviceOrClassname) : $serviceOrClassname);
42
    }
43
44 6
    public function setObjectFactory($objectFactory)
45
    {
46 6
        $this->objectFactory = $objectFactory;
47 6
    }
48
49 6
    public function setObjectTransformer($objectTransformer)
50
    {
51 6
        $this->objectTransformer = $objectTransformer;
52 6
    }
53
54
    /*
55
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::reader()
56
     */
57 2
    public function reader()
58
    {
59 2
        $reader = new ServiceReader(
60 2
            $this->callable,
61 2
            $this->arguments,
62 2
            $this->objectTransformer
0 ignored issues
show
Unused Code introduced by
The call to ServiceReader::__construct() has too many arguments starting with $this->objectTransformer.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
63 2
        );
64
65 2
        return $reader;
66
    }
67
68
    /*
69
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::writer()
70
     */
71 1
    public function writer()
72
    {
73 1
        $writer = new ServiceWriter(
74 1
            $this->callable,
75 1
            $this->objectFactory
76 1
        );
77
78 1
        return $writer;
79
    }
80
81
    /*
82
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::info()
83
     */
84 1
    public function info()
85
    {
86 1
        return new StorageInfo(array(
87 1
            'name' => get_class($this->callable[0]) . '->' . $this->callable[1],
88 1
            'format' => 'Service method',
89 1
            'count' => count($this->reader())
90 1
        ));
91
    }
92
93
    /*
94
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::getFields()
95
     */
96
    public function getFields()
97
    {
98
        return $this->reader()->getFields();
99
    }
100
}
101