Completed
Push — master ( 4e986c...7c30c4 )
by Tim
19s queued 12s
created

AbstractCustomerAddressSubject   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 105
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A getCleanUpColumns() 0 3 1
A setLastEntityId() 0 3 1
A storeViewHasBeenProcessed() 0 3 1
A getStoreWebsiteIdByCode() 0 12 2
A getLastEntityId() 0 3 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Subjects\AbstractAddressCustomerSubject
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 2018 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-customer-address
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Customer\Address\Subjects;
22
23
use TechDivision\Import\Subjects\AbstractEavSubject;
24
use TechDivision\Import\Subjects\EntitySubjectInterface;
25
use TechDivision\Import\Customer\Address\Utils\MemberNames;
26
use TechDivision\Import\Customer\Address\Utils\RegistryKeys;
27
use TechDivision\Import\Customer\Address\Utils\ConfigurationKeys;
28
29
/**
30
 * The abstract customer subject implementation that provides basic customer address
31
 * handling business logic.
32
 *
33
 * @author    Tim Wagner <[email protected]>
34
 * @copyright 2018 TechDivision GmbH <[email protected]>
35
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
36
 * @link      https://github.com/techdivision/import-customer-address
37
 * @link      http://www.techdivision.com
38
 */
39
abstract class AbstractCustomerAddressSubject extends AbstractEavSubject implements EntitySubjectInterface
40
{
41
42
    /**
43
     * The ID of the product that has been created recently.
44
     *
45
     * @var string
46
     */
47
    protected $lastEntityId;
48
49
    /**
50
     * The available store websites.
51
     *
52
     * @var array
53
     */
54
    protected $storeWebsites = array();
55
56
    /**
57
     * Set's the ID of the product that has been created recently.
58
     *
59
     * @param string $lastEntityId The entity ID
60
     *
61
     * @return void
62
     */
63
    public function setLastEntityId($lastEntityId)
64
    {
65
        $this->lastEntityId = $lastEntityId;
66
    }
67
68
    /**
69
     * Return's the ID of the product that has been created recently.
70
     *
71
     * @return string The entity Id
72
     */
73
    public function getLastEntityId()
74
    {
75
        return $this->lastEntityId;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->lastEntityId returns the type string which is incompatible with the return type mandated by TechDivision\Import\Subj...face::getLastEntityId() of integer.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
76
    }
77
78
    /**
79
     * Queries whether or not the passed PK and store view code has already been processed.
80
     *
81
     * @param string $pk            The PK to check been processed
82
     * @param string $storeViewCode The store view code to check been processed
83
     *
84
     * @return boolean TRUE if the PK and store view code has been processed, else FALSE
85
     */
86
    public function storeViewHasBeenProcessed($pk, $storeViewCode)
0 ignored issues
show
Unused Code introduced by
The parameter $pk is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    public function storeViewHasBeenProcessed(/** @scrutinizer ignore-unused */ $pk, $storeViewCode)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $storeViewCode is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    public function storeViewHasBeenProcessed($pk, /** @scrutinizer ignore-unused */ $storeViewCode)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88
        return false;
89
    }
90
91
    /**
92
     * Intializes the previously loaded global data for exactly one bunch.
93
     *
94
     * @param string $serial The serial of the actual import
95
     *
96
     * @return void
97
     */
98
    public function setUp($serial)
99
    {
100
101
        // load the status of the actual import
102
        $status = $this->getRegistryProcessor()->getAttribute($serial);
103
104
        // load the global data we've prepared initially
105
        $this->storeWebsites =  $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::STORE_WEBSITES];
106
107
        // invoke the parent method
108
        parent::setUp($serial);
109
    }
110
111
    /**
112
     * Return's the store website for the passed code.
113
     *
114
     * @param string $code The code of the store website to return the ID for
115
     *
116
     * @return integer The store website ID
117
     * @throws \Exception Is thrown, if the store website with the requested code is not available
118
     */
119
    public function getStoreWebsiteIdByCode($code)
120
    {
121
122
        // query whether or not, the requested store website is available
123
        if (isset($this->storeWebsites[$code])) {
124
            return (integer) $this->storeWebsites[$code][MemberNames::WEBSITE_ID];
125
        }
126
127
        // throw an exception, if not
128
        throw new \Exception(
129
            $this->appendExceptionSuffix(
130
                sprintf('Found invalid website code %s', $code)
131
            )
132
        );
133
    }
134
135
    /**
136
     * Merge the columns from the configuration with all image type columns to define which
137
     * columns should be cleaned-up.
138
     *
139
     * @return array The columns that has to be cleaned-up
140
     */
141
    public function getCleanUpColumns()
142
    {
143
        return $this->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getConfigu...CLEAN_UP_EMPTY_COLUMNS) returns the type string which is incompatible with the documented return type array.
Loading history...
144
    }
145
}
146