Completed
Push — 8.x ( 824af6 )
by Tim
09:11
created

PrimaryKeyUtil   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 51
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPrimaryKeyMemberName() 0 14 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Utils\PrimaryKeyUtil
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Utils;
22
23
use TechDivision\Import\ConfigurationInterface;
24
25
/**
26
 * Utility class for edition based primary key handling.
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
32
 * @link      http://www.techdivision.com
33
 */
34
class PrimaryKeyUtil implements PrimaryKeyUtilInterface
35
{
36
37
    /**
38
     * The configuration instance.
39
     *
40
     * @var \TechDivision\Import\ConfigurationInterface
41
     */
42
    protected $configuration;
43
44
    /**
45
     * The mapping for the edition to primary key member name.
46
     *
47
     * @var array
48
     */
49
    protected $editionPrimaryKeyMemberNameMappings = array(
50
        EditionNamesInterface::EE => MemberNames::ROW_ID,
51
        EditionNamesInterface::CE => MemberNames::ENTITY_ID
52
    );
53
54
    /**
55
     * Construct a new instance.
56
     *
57
     * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance
58
     */
59
    public function __construct(ConfigurationInterface $configuration)
60
    {
61
        $this->configuration = $configuration;
62
    }
63
64
    /**
65
     * Returns the primary key member name for the actual Magento edition.
66
     *
67
     * @return string The primary key member name
68
     * @throws \Exception Is thrown if the edition is not supported/available
69
     */
70
    public function getPrimaryKeyMemberName()
71
    {
72
73
        // make sure the edition name is in upper cases
74
        $editionName = strtoupper($this->configuration->getMagentoEdition());
75
76
        // return the primary key member name for the actual edition
77
        if (isset($this->editionPrimaryKeyMemberNameMappings[$editionName])) {
78
            return $this->editionPrimaryKeyMemberNameMappings[$editionName];
79
        }
80
81
        // throw an exception if the edition is NOT supported/available
82
        throw new \Exception(sprintf('Found not supported/available Magento edition name "%s"', $editionName));
83
    }
84
}
85