Completed
Push — 15.x ( 84e4c2...66410f )
by Tim
02:43
created

AbstractValidatorCallback::getValidations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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()));
0 ignored issues
show
Unused Code introduced by
The call to LoaderInterface::load() has too many arguments starting with $subject->getConfiguration().

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...
Documentation introduced by
$this->getLoader()->load...ct->getConfiguration()) is of type object<ArrayAccess>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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