Completed
Push — 10.x ( ad614f )
by Tim
04:36
created

EeBunchSubject::getPrimaryKeyMemberName()   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 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Category\Ee\Subjects\EeBunchSubject
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-category-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Category\Ee\Subjects;
22
23
use TechDivision\Import\Utils\RegistryKeys;
24
use TechDivision\Import\Category\Subjects\BunchSubject;
25
use TechDivision\Import\Category\Ee\Utils\MemberNames;
26
27
/**
28
 * A SLSB that handles the process to import category bunches.
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-category-ee
34
 * @link      http://www.techdivision.com
35
 */
36
class EeBunchSubject extends BunchSubject
37
{
38
39
    /**
40
     * The row ID of the product that has been created recently.
41
     *
42
     * @var integer
43
     */
44
    protected $lastRowId;
45
46
    /**
47
     * The mapping for the paths to the created row IDs.
48
     *
49
     * @var array
50
     */
51
    protected $pathRowIdMapping = array();
52
53
    /**
54
     * Intializes the previously loaded global data for exactly one bunch.
55
     *
56
     * @param string $serial The serial of the actual import
57
     *
58
     * @return void
59
     */
60
    public function setUp($serial)
61
    {
62
63
        // load the available category path => row ID mappings
64
        foreach ($this->getCategoryBunchProcessor()->getCategoriesWithResolvedPath() as $resolvedPath => $category) {
65
            $this->pathRowIdMapping[$resolvedPath] = $category[MemberNames::ROW_ID];
66
        }
67
68
        // prepare the callbacks
69
        parent::setUp($serial);
70
    }
71
72
    /**
73
     * Set's the row ID of the product that has been created recently.
74
     *
75
     * @param string $lastRowId The row ID
76
     *
77
     * @return void
78
     */
79 1
    public function setLastRowId($lastRowId)
80
    {
81 1
        $this->lastRowId = $lastRowId;
0 ignored issues
show
Documentation Bug introduced by
The property $lastRowId was declared of type integer, but $lastRowId is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
82 1
    }
83
84
    /**
85
     * Return's the row ID of the product that has been created recently.
86
     *
87
     * @return string The row Id
88
     */
89 1
    public function getLastRowId()
90
    {
91 1
        return $this->lastRowId;
92
    }
93
94
    /**
95
     * Add the passed path => row ID mapping.
96
     *
97
     * @param string $path The path
98
     *
99
     * @return void
100
     */
101
    public function addPathRowIdMapping($path)
102
    {
103
        $this->pathRowIdMapping[$path] = $this->getLastRowId();
104
    }
105
106
    /**
107
     * Removes the mapping, e. g. when a category has been deleted.
108
     *
109
     * @param string $path The path to delete the mapping for
110
     *
111
     * @return void
112
     */
113
    public function removePathRowIdMapping($path)
114
    {
115
        unset($this->pathRowIdMapping[$path]);
116
    }
117
118
    /**
119
     * Return's the entity ID for the passed path.
120
     *
121
     * @param string $path The path to return the entity ID for
122
     *
123
     * @return integer The mapped entity ID
124
     * @throws \Exception Is thrown, if the path can not be mapped
125
     */
126
    public function mapPathRowId($path)
127
    {
128
129
        // query whether or not a entity ID for the passed path has been mapped
130
        if (isset($this->pathRowIdMapping[$path])) {
131
            return $this->pathRowIdMapping[$path];
132
        }
133
134
        // throw an exception if not
135
        throw new \Exception(sprintf('Can\'t map path %s to any row ID', $path));
136
    }
137
138
    /**
139
     * Return's the PK column name to create the product => attribute relation.
140
     *
141
     * @return string The PK column name
142
     */
143
    protected function getPrimaryKeyMemberName()
144
    {
145
        return MemberNames::ROW_ID;
146
    }
147
}
148