|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Callbacks\AbstractValidatorCallback |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Callbacks; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Loaders\LoaderInterface; |
|
24
|
|
|
use TechDivision\Import\Subjects\SubjectInterface; |
|
25
|
|
|
use TechDivision\Import\Services\RegistryProcessorInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Abstract callback implementation the validate the value for an specific attribute. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
abstract class AbstractValidatorCallback implements CallbackInterface, CallbackFactoryInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The loader instance for the custom validations. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \TechDivision\Import\Loaders\LoaderInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $loader; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The array that contains the allowed values found in the configuration. |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $validations = array(); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Initializes the callback with the loader instance. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \TechDivision\Import\Loaders\LoaderInterface $loader The loader for the validations |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct(LoaderInterface $loader) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->loader = $loader; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Will be invoked by the callback visitor when a factory has been defined to create the callback instance. |
|
65
|
|
|
* |
|
66
|
|
|
* @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance |
|
67
|
|
|
* |
|
68
|
|
|
* @return \TechDivision\Import\Callbacks\CallbackInterface The callback instance |
|
69
|
|
|
*/ |
|
70
|
|
|
public function createCallback(SubjectInterface $subject) |
|
71
|
|
|
{ |
|
72
|
|
|
|
|
73
|
|
|
// query whether or not the configuration value is available |
|
74
|
|
|
$this->setValidations($this->getLoader()->load($subject->getConfiguration())); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
// return the initialized instance |
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return's the loader instance for the custom validations. |
|
82
|
|
|
* |
|
83
|
|
|
* @return \TechDivision\Import\Loaders\LoaderInterface The loader instance |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function getLoader() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->loader; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Set's the validations. |
|
92
|
|
|
* |
|
93
|
|
|
* @param array $validations The available validations |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function setValidations(array $validations) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->validations = $validations; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return's the validations for the attribute with the passed code. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string|null $attributeCode The code of the attribute to return the validations for |
|
104
|
|
|
* |
|
105
|
|
|
* @return array The allowed values for the attribute with the passed code |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function getValidations($attributeCode = null) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->validations; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
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
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.