Completed
Push — master ( 46dc9d...2f0783 )
by Markus
03:36
created

ServiceStorage::getCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 3
    public function __construct(callable $callable, $arguments=array(), $objectMapper=null)
24
    {
25 3
        $this->callable = $callable;
26 3
        $this->arguments = $arguments;
27 3
        $this->setObjectFactory($objectMapper);
28 3
        $this->setObjectTransformer($objectMapper);
29
30 3
        if (!is_callable($callable)) {
31
            throw new \InvalidArgumentException("Given callable is not a callable");
32
        }
33 3
    }
34
35
    /**
36
     * @return callable
37
     */
38
    public function getCallable()
39
    {
40
        return $this->callable;
41
    }
42
43 3
    public function setObjectFactory($objectFactory)
44
    {
45 3
        $this->objectFactory = $objectFactory;
46 3
    }
47
48 3
    public function setObjectTransformer($objectTransformer)
49
    {
50 3
        $this->objectTransformer = $objectTransformer;
51 3
    }
52
53
    /*
54
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::reader()
55
     */
56 1
    public function reader()
57
    {
58 1
        $reader = new ServiceReader(
59 1
            $this->callable,
60 1
            $this->arguments,
61 1
            $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...
62 1
        );
63
64 1
        return $reader;
65
    }
66
67
    /*
68
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::writer()
69
     */
70 1
    public function writer()
71
    {
72 1
        $writer = new ServiceWriter(
73 1
            $this->callable,
74 1
            $this->objectFactory
75 1
        );
76
77 1
        return $writer;
78
    }
79
80
    /*
81
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::info()
82
     */
83 View Code Duplication
    public function info()
0 ignored issues
show
Duplication introduced by
This method 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...
84
    {
85
        return new StorageInfo(array(
86
            'name' => $this->callable.'',
87
            'format' => 'Service method',
88
            'size' => 0,
89
            'count' => count($this->reader())
90
        ));
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