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 |
|
|
|
|
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
|
|
|
|
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.