Completed
Push — 19.x ( b52937...9de1c0 )
by Tim
06:07
created

TaxClassValidatorCallback   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 21 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Converter\Callbacks\TaxClassValidatorCallback
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-product
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Callbacks;
22
23
use TechDivision\Import\Callbacks\AbstractValidatorCallback;
24
25
/**
26
 * Tax class validator callback implementation.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2019 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product
32
 * @link      http://www.techdivision.com
33
 */
34
class TaxClassValidatorCallback extends AbstractValidatorCallback
35
{
36
37
    /**
38
     * Will be invoked by a observer it has been registered for.
39
     *
40
     * @param string|null $attributeCode  The code of the attribute that has to be validated
41
     * @param string|null $attributeValue The attribute value to be validated
42
     *
43
     * @return mixed The modified value
44
     */
45
    public function handle($attributeCode = null, $attributeValue = null)
46
    {
47
48
        // the validations for the attribute with the given code
49
        $validations = $this->getValidations();
50
51
        // if the passed value is in the array, return immediately
52
        if (in_array($attributeValue, $validations)) {
53
            return;
54
        }
55
56
        // throw an exception if the value is NOT in the array
57
        throw new \InvalidArgumentException(
58
            sprintf(
59
                'Found invalid value "%s" for column "%s" (must be one of: "%s")',
60
                $attributeValue,
61
                $attributeCode,
62
                implode(', ', $validations)
63
            )
64
        );
65
    }
66
}
67