Completed
Pull Request — master (#26)
by Tim
08:52
created

AbstractAttributeSubject::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Subjects\AbstractAttributeSubject
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 2016 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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Subjects;
22
23
use TechDivision\Import\Subjects\AbstractSubject;
24
use TechDivision\Import\Subjects\EntitySubjectInterface;
25
use TechDivision\Import\Utils\RegistryKeys;
26
27
/**
28
 * The abstract product subject implementation that provides basic attribute
29
 * handling business logic.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2016 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-attribute
35
 * @link      http://www.techdivision.com
36
 */
37
abstract class AbstractAttributeSubject extends AbstractSubject implements AttributeSubjectInterface, EntitySubjectInterface
38
{
39
40
    /**
41
     * The array with the available entity types.
42
     *
43
     * @var array
44
     */
45
    protected $entityTypes = array();
46
47
    /**
48
     * Mappings for attribute code => CSV column header.
49
     *
50
     * @var array
51
     */
52
    protected $headerMappings = array();
53
54
    /**
55
     * Intializes the previously loaded global data for exactly one bunch.
56
     *
57
     * @param string $serial The serial of the actual import
58
     *
59
     * @return void
60
     */
61
    public function setUp($serial)
62
    {
63
64
        // load the status of the actual import
65
        $status = $this->getRegistryProcessor()->getAttribute($serial);
66
67
        // load the global data we've prepared initially
68
        $this->entityTypes = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::ENTITY_TYPES];
69
70
        // prepare the callbacks
71
        parent::setUp($serial);
72
    }
73
74
    /**
75
     * Return's the header mappings for the actual entity.
76
     *
77
     * @return array The header mappings
78
     */
79
    public function getHeaderMappings()
80
    {
81
        return $this->headerMappings;
82
    }
83
84
    /**
85
     * Return's the entity type for the passed code.
86
     *
87
     * @param string $entityTypeCode The entity type code
88
     *
89
     * @return array The requested entity type
90
     * @throws \Exception Is thrown, if the entity type with the passed code is not available
91
     */
92
    public function getEntityType($entityTypeCode)
93
    {
94
95
        // query whether or not, the entity type with the passed code is available
96
        if (isset($this->entityTypes[$entityTypeCode])) {
97
            return $this->entityTypes[$entityTypeCode];
98
        }
99
100
        // throw an exception, if not
101
        throw new \Exception(
102
            sprintf(
103
                'Can\'t find entity type with code %s in file %s on line %d',
104
                $entityTypeCode,
105
                $this->getFilename(),
106
                $this->getLineNumber()
107
            )
108
        );
109
    }
110
}
111