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
|
5 |
|
public function __construct(callable $callable, $arguments=array(), $objectMapper=null) |
24
|
|
|
{ |
25
|
5 |
|
$this->callable = $callable; |
26
|
5 |
|
$this->arguments = $arguments; |
27
|
5 |
|
$this->setObjectFactory($objectMapper); |
28
|
5 |
|
$this->setObjectTransformer($objectMapper); |
29
|
5 |
|
} |
30
|
|
|
|
31
|
1 |
|
public function isCalledService($service) |
32
|
|
|
{ |
33
|
1 |
|
return $this->callable[0] === $service; |
34
|
|
|
} |
35
|
|
|
|
36
|
5 |
|
public function setObjectFactory($objectFactory) |
37
|
|
|
{ |
38
|
5 |
|
$this->objectFactory = $objectFactory; |
39
|
5 |
|
} |
40
|
|
|
|
41
|
5 |
|
public function setObjectTransformer($objectTransformer) |
42
|
|
|
{ |
43
|
5 |
|
$this->objectTransformer = $objectTransformer; |
44
|
5 |
|
} |
45
|
|
|
|
46
|
|
|
/* |
47
|
|
|
* (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::reader() |
48
|
|
|
*/ |
49
|
2 |
|
public function reader() |
50
|
|
|
{ |
51
|
2 |
|
$reader = new ServiceReader( |
52
|
2 |
|
$this->callable, |
53
|
2 |
|
$this->arguments, |
54
|
2 |
|
$this->objectTransformer |
|
|
|
|
55
|
2 |
|
); |
56
|
|
|
|
57
|
2 |
|
return $reader; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/* |
61
|
|
|
* (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::writer() |
62
|
|
|
*/ |
63
|
1 |
|
public function writer() |
64
|
|
|
{ |
65
|
1 |
|
$writer = new ServiceWriter( |
66
|
1 |
|
$this->callable, |
67
|
1 |
|
$this->objectFactory |
68
|
1 |
|
); |
69
|
|
|
|
70
|
1 |
|
return $writer; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/* |
74
|
|
|
* (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::info() |
75
|
|
|
*/ |
76
|
1 |
|
public function info() |
77
|
|
|
{ |
78
|
1 |
|
return new StorageInfo(array( |
79
|
1 |
|
'name' => get_class($this->callable[0]).'->'.$this->callable[1], |
80
|
1 |
|
'format' => 'Service method', |
81
|
1 |
|
'count' => count($this->reader()) |
82
|
1 |
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/* |
86
|
|
|
* (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::getFields() |
87
|
|
|
*/ |
88
|
|
|
public function getFields() |
89
|
|
|
{ |
90
|
|
|
return $this->reader()->getFields(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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.