Completed
Push — 19.x ( f78ed0 )
by Tim
01:55
created

RmaCallback::__construct()   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
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Ee\Callbacks\RmaCallback
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 2020 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-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Ee\Callbacks;
22
23
use TechDivision\Import\Product\Ee\Utils\ColumnKeys;
24
use TechDivision\Import\Product\Ee\Utils\RmaKeysInterface;
25
use TechDivision\Import\Product\Callbacks\AbstractProductImportCallback;
26
use TechDivision\Import\Observers\AttributeCodeAndValueAwareObserverInterface;
27
28
/**
29
 * A callback implementation that converts the passed RMA key.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2020 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import-product-ee
35
 * @link      http://www.techdivision.com
36
 */
37
class RmaCallback extends AbstractProductImportCallback
38
{
39
40
    /**
41
     * The utility instance with the RMA keys.
42
     *
43
     * @var \TechDivision\Import\Product\Ee\Utils\RmaKeysInterface
44
     */
45
    protected $rmaKeys;
46
47
    /**
48
     * Initializes the callback with the RMA keys instance.
49
     *
50
     * @param \TechDivision\Import\Product\Ee\Utils\RmaKeysInterface $rmaKeys The instance
51
     */
52
    public function __construct(RmaKeysInterface $rmaKeys)
53
    {
54
        $this->rmaKeys = $rmaKeys;
55
    }
56
57
    /**
58
     * Will be invoked by a observer it has been registered for.
59
     *
60
     * @param \TechDivision\Import\Observers\AttributeCodeAndValueAwareObserverInterface|null $observer The observer
61
     *
62
     * @return int The converted value
63
     */
64
    public function handle(AttributeCodeAndValueAwareObserverInterface $observer = null) : int
65
    {
66
67
        // set the observer
68
        $this->setObserver($observer);
0 ignored issues
show
Bug introduced by
It seems like $observer defined by parameter $observer on line 64 can be null; however, TechDivision\Import\Call...Callback::setObserver() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
69
70
        // replace the passed attribute value into the visibility ID
71
        return $this->getRmaKeys()->get($this->getValue(ColumnKeys::IS_RETURNABLE));
72
    }
73
74
    /**
75
     * Return's the instance with the RMA keys.
76
     *
77
     * @return \TechDivision\Import\Product\Ee\Utils\RmaKeysInterface The instance
78
     */
79
    protected function getRmaKeys() : RmaKeysInterface
80
    {
81
        return $this->rmaKeys;
82
    }
83
}
84