Completed
Push — master ( b2ff41...3eced2 )
by Tim
14s
created

findOneByAttributeCodeAndStoreIdAndValue()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 11

Duplication

Lines 26
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 26
loc 26
ccs 0
cts 15
cp 0
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 3
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\EavAttributeOptionValueCachedRepository
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Repositories;
22
23
use TechDivision\Import\Utils\MemberNames;
24
25
/**
26
 * Cached repository implementation to load EAV attribute option value data.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 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 EavAttributeOptionValueRepository extends AbstractCachedRepository implements EavAttributeOptionValueRepositoryInterface
35
{
36
37
    /**
38
     * The prepared statement to load the existing EAV attribute option values.
39
     *
40
     * @var \PDOStatement
41
     */
42
    protected $eavAttributeOptionValuesStmt;
43
44
    /**
45
     * The prepared statement to load an existing EAV attribute option value by its option id and store ID
46
     *
47
     * @var \PDOStatement
48
     */
49
    protected $eavAttributeOptionValueByOptionIdAndStoreIdStmt;
50
51
    /**
52
     * The prepared statement to load an existing EAV attribute option value by its attribute code, store ID and value.
53
     *
54
     * @var \PDOStatement
55
     */
56
    protected $eavAttributeOptionValueByAttributeCodeAndStoreIdAndValueStmt;
57
58
    /**
59
     * Initializes the repository's prepared statements.
60
     *
61
     * @return void
62
     */
63
    public function init()
64
    {
65
66
        // load the utility class name
67
        $utilityClassName = $this->getUtilityClassName();
68
69
        // initialize the prepared statements
70
        $this->eavAttributeOptionValuesStmt =
71
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::EAV_ATTRIBUTE_OPTION_VALUES));
72
73
        // initialize the prepared statements
74
        $this->eavAttributeOptionValueByOptionIdAndStoreIdStmt =
75
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_OPTION_ID_AND_STORE_ID));
76
77
        // initialize the prepared statements
78
        $this->eavAttributeOptionValueByAttributeCodeAndStoreIdAndValueStmt =
79
            $this->getConnection()->prepare($this->getUtilityClass()->find($utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE));
80
    }
81
82
    /**
83
     * Load's and return's the available EAV attribute option values.
84
     *
85
     * @return array The EAV attribute option values
86
     */
87
    public function findAll()
88
    {
89
90
        // load and return all available EAV attribute option values
91
        $this->eavAttributeOptionValuesStmt->execute(array());
92
        return $this->eavAttributeOptionValuesStmt->fetchAll(\PDO::FETCH_ASSOC);
93
    }
94
95
    /**
96
     * Load's and return's the EAV attribute option value with the passed option ID and store ID
97
     *
98
     * @param string  $optionId The option ID of the attribute option
99
     * @param integer $storeId  The store ID of the attribute option to load
100
     *
101
     * @return array The EAV attribute option value
102
     */
103 View Code Duplication
    public function findOneByOptionIdAndStoreId($optionId, $storeId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
106
        // the parameters of the EAV attribute option to load
107
        $params = array(
108
            MemberNames::OPTION_ID => $optionId,
109
            MemberNames::STORE_ID  => $storeId,
110
        );
111
112
        // load the utility class name
113
        $utilityClassName = $this->getUtilityClassName();
114
115
        // prepare the cache key
116
        $cacheKey = $this->cacheKey($utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_OPTION_ID_AND_STORE_ID, $params);
117
118
        // query whether or not the result has been cached
119
        if ($this->notCached($cacheKey)) {
120
            // load and return the EAV attribute option value with the passed parameters
121
            $this->eavAttributeOptionValueByOptionIdAndStoreIdStmt->execute($params);
122
            $this->toCache($cacheKey, $this->eavAttributeOptionValueByOptionIdAndStoreIdStmt->fetch(\PDO::FETCH_ASSOC));
123
        }
124
125
        // return the value from the cache
126
        return $this->fromCache($cacheKey);
127
    }
128
129
    /**
130
     * Load's and return's the EAV attribute option value with the passed code, store ID and value.
131
     *
132
     * @param string  $attributeCode The code of the EAV attribute option to load
133
     * @param integer $storeId       The store ID of the attribute option to load
134
     * @param string  $value         The value of the attribute option to load
135
     *
136
     * @return array The EAV attribute option value
137
     */
138 View Code Duplication
    public function findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    {
140
141
        // the parameters of the EAV attribute option to load
142
        $params = array(
143
            MemberNames::ATTRIBUTE_CODE => $attributeCode,
144
            MemberNames::STORE_ID       => $storeId,
145
            MemberNames::VALUE          => $value
146
        );
147
148
        // load the utility class name
149
        $utilityClassName = $this->getUtilityClassName();
150
151
        // prepare the cache key
152
        $cacheKey = $this->cacheKey($utilityClassName::EAV_ATTRIBUTE_OPTION_VALUE_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE, $params);
153
154
        // query whether or not the result has been cached
155
        if ($this->notCached($cacheKey)) {
156
            // load and return the EAV attribute option value with the passed parameters
157
            $this->eavAttributeOptionValueByAttributeCodeAndStoreIdAndValueStmt->execute($params);
158
            $this->toCache($cacheKey, $this->eavAttributeOptionValueByAttributeCodeAndStoreIdAndValueStmt->fetch(\PDO::FETCH_ASSOC));
159
        }
160
161
        // return the value from the cache
162
        return $this->fromCache($cacheKey);
163
    }
164
}
165