Code Duplication    Length = 38-39 lines in 2 locations

src/Callbacks/BooleanValidatorCallback.php 1 location

@@ 32-70 (lines=39) @@
29
 * @link      https://github.com/techdivision/import-product
30
 * @link      http://www.techdivision.com
31
 */
32
class BooleanValidatorCallback extends ArrayValidatorCallback
33
{
34
35
    /**
36
     * Will be invoked by the observer it has been registered for.
37
     *
38
     * @param string|null $attributeCode  The code of the attribute that has to be validated
39
     * @param string|null $attributeValue The attribute value to be validated
40
     *
41
     * @return mixed The modified value
42
     */
43
    public function handle($attributeCode = null, $attributeValue = null)
44
    {
45
46
        // load the subject instance
47
        $subject = $this->getSubject();
48
49
        // explode the additional attributes
50
        if ($this->isNullable($optionValues = $subject->explode($attributeValue, '='))) {
51
            return;
52
        }
53
54
        // load the validations
55
        $validations = $this->getValidations($attributeCode);
56
57
        // iterate over the attributes and append them to the row
58
        foreach ($optionValues as $optionValue) {
59
            // query whether or not a boolean value has been specified
60
            if (in_array(strtolower($optionValue), $validations)) {
61
                continue;
62
            }
63
64
            // throw an exception if the value is NOT in the array
65
            throw new \InvalidArgumentException(
66
                sprintf('Found invalid boolean value "%s" for attribute with code "%s"', $optionValue, $attributeCode)
67
            );
68
        }
69
    }
70
}
71

src/Callbacks/SelectValidatorCallback.php 1 location

@@ 32-69 (lines=38) @@
29
 * @link      https://github.com/techdivision/import-product
30
 * @link      http://www.techdivision.com
31
 */
32
class SelectValidatorCallback extends IndexedArrayValidatorCallback
33
{
34
35
    /**
36
     * Will be invoked by the observer it has been registered for.
37
     *
38
     * @param string|null $attributeCode  The code of the attribute that has to be validated
39
     * @param string|null $attributeValue The attribute value to be validated
40
     *
41
     * @return mixed The modified value
42
     */
43
    public function handle($attributeCode = null, $attributeValue = null)
44
    {
45
46
        // load the subject instance
47
        $subject = $this->getSubject();
48
49
        // explode the additional attributes
50
        if ($this->isNullable($optionValues = $subject->explode($attributeValue, '='))) {
51
            return;
52
        }
53
54
        $validations = $this->getValidations($attributeCode);
55
56
        // iterate over the attributes and append them to the row
57
        foreach ($optionValues as $optionValue) {
58
59
            if (in_array($optionValue, $validations)) {
60
                continue;
61
            }
62
63
            // throw an exception if the value is NOT in the array
64
            throw new \InvalidArgumentException(
65
                sprintf('Found invalid option value "%s" for attribute with code "%s"', $optionValue, $attributeCode)
66
            );
67
        }
68
    }
69
}
70