getCustomerAttributesByEntityId()   A
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 33
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 33
rs 9.2222
cc 6
nc 32
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Assemblers\CustomerAttributeAssembler
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2018 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-customer
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Assemblers;
16
17
use TechDivision\Import\Customer\Utils\MemberNames;
18
use TechDivision\Import\Customer\Repositories\CustomerIntRepositoryInterface;
19
use TechDivision\Import\Customer\Repositories\CustomerTextRepositoryInterface;
20
use TechDivision\Import\Customer\Repositories\CustomerVarcharRepositoryInterface;
21
use TechDivision\Import\Customer\Repositories\CustomerDecimalRepositoryInterface;
22
use TechDivision\Import\Customer\Repositories\CustomerDatetimeRepositoryInterface;
23
24
/**
25
 * Assembler implementation that provides functionality to assemble customer attribute data.
26
 *
27
 * @author    Tim Wagner <[email protected]>
28
 * @copyright 2018 TechDivision GmbH <[email protected]>
29
 * @license   https://opensource.org/licenses/MIT
30
 * @link      https://github.com/techdivision/import-customer
31
 * @link      http://www.techdivision.com
32
 */
33
class CustomerAttributeAssembler implements CustomerAttributeAssemblerInterface
34
{
35
36
    /**
37
     * The customer datetime repository instance.
38
     *
39
     * @var \TechDivision\Import\Customer\Repositories\CustomerDatetimeRepositoryInterface
40
     */
41
    protected $customerDatetimeRepository;
42
43
    /**
44
     * The customer decimal repository instance.
45
     *
46
     * @var \TechDivision\Import\Customer\Repositories\CustomerDecimalRepositoryInterface
47
     */
48
    protected $customerDecimalRepository;
49
50
    /**
51
     * The customer integer repository instance.
52
     *
53
     * @var \TechDivision\Import\Customer\Repositories\CustomerIntRepositoryInterface
54
     */
55
    protected $customerIntRepository;
56
57
    /**
58
     * The customer text repository instance.
59
     *
60
     * @var \TechDivision\Import\Customer\Repositories\CustomerTextRepositoryInterface
61
     */
62
    protected $customerTextRepository;
63
64
    /**
65
     * The customer varchar repository instance.
66
     *
67
     * @var \TechDivision\Import\Customer\Repositories\CustomerVarcharRepositoryInterface
68
     */
69
    protected $customerVarcharRepository;
70
71
    /**
72
     * Initializes the assembler with the necessary repositories.
73
     *
74
     * @param \TechDivision\Import\Customer\Repositories\CustomerDatetimeRepositoryInterface $customerDatetimeRepository The customer datetime repository instance
75
     * @param \TechDivision\Import\Customer\Repositories\CustomerDecimalRepositoryInterface  $customerDecimalRepository  The customer decimal repository instance
76
     * @param \TechDivision\Import\Customer\Repositories\CustomerIntRepositoryInterface      $customerIntRepository      The customer integer repository instance
77
     * @param \TechDivision\Import\Customer\Repositories\CustomerTextRepositoryInterface     $customerTextRepository     The customer text repository instance
78
     * @param \TechDivision\Import\Customer\Repositories\CustomerVarcharRepositoryInterface  $customerVarcharRepository  The customer varchar repository instance
79
     */
80
    public function __construct(
81
        CustomerDatetimeRepositoryInterface $customerDatetimeRepository,
82
        CustomerDecimalRepositoryInterface $customerDecimalRepository,
83
        CustomerIntRepositoryInterface $customerIntRepository,
84
        CustomerTextRepositoryInterface $customerTextRepository,
85
        CustomerVarcharRepositoryInterface $customerVarcharRepository
86
    ) {
87
        $this->customerDatetimeRepository = $customerDatetimeRepository;
88
        $this->customerDecimalRepository = $customerDecimalRepository;
89
        $this->customerIntRepository = $customerIntRepository;
90
        $this->customerTextRepository = $customerTextRepository;
91
        $this->customerVarcharRepository = $customerVarcharRepository;
92
    }
93
94
    /**
95
     * Intializes the existing attributes for the entity with the passed entity ID.
96
     *
97
     * @param integer $entityId The entity ID of the entity to load the attributes for
98
     *
99
     * @return array The entity attributes
100
     */
101
    public function getCustomerAttributesByEntityId($entityId)
102
    {
103
104
        // initialize the array for the attributes
105
        $attributes = array();
106
107
        // load the datetime attributes
108
        foreach ($this->customerDatetimeRepository->findAllByEntityId($entityId) as $attribute) {
109
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
110
        }
111
112
        // load the decimal attributes
113
        foreach ($this->customerDecimalRepository->findAllByEntityId($entityId) as $attribute) {
114
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
115
        }
116
117
        // load the integer attributes
118
        foreach ($this->customerIntRepository->findAllByEntityId($entityId) as $attribute) {
119
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
120
        }
121
122
        // load the text attributes
123
        foreach ($this->customerTextRepository->findAllByEntityId($entityId) as $attribute) {
124
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
125
        }
126
127
        // load the varchar attributes
128
        foreach ($this->customerVarcharRepository->findAllByEntityId($entityId) as $attribute) {
129
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
130
        }
131
132
        // return the array with the attributes
133
        return $attributes;
134
    }
135
}
136