Completed
Push — 17.x ( 3fdb9b...8eca03 )
by Tim
02:21
created

AttributeOptionSwatchRepository::findOneByAttributeCodeAndStoreIdAndValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 11
cp 0
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository
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\Repositories;
22
23
use TechDivision\Import\Attribute\Utils\MemberNames;
24
use TechDivision\Import\Attribute\Utils\SqlStatementKeys;
25
use TechDivision\Import\Repositories\AbstractRepository;
26
27
/**
28
 * Repository implementation to load EAV attribute option swatch data.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 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-attribute
34
 * @link      http://www.techdivision.com
35
 */
36
class AttributeOptionSwatchRepository extends AbstractRepository implements AttributeOptionSwatchRepositoryInterface
37
{
38
39
    /**
40
     * The prepared statement to load an existing EAV attribute option swatch by its option ID and store ID
41
     *
42
     * @var \PDOStatement
43
     */
44
    protected $attributeOptionSwatchByOptionIdAndStoreIdStmt;
45
46
    /**
47
     * The prepared statement to load an existing EAV attribute option swatch by its attribute code, store ID. value and type.
48
     *
49
     * @var \PDOStatement
50
     */
51
    protected $attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt;
52
53
    /**
54
     * Initializes the repository's prepared statements.
55
     *
56
     * @return void
57
     */
58
    public function init()
59
    {
60
61
        // initialize the prepared statements
62
        $this->attributeOptionSwatchByOptionIdAndStoreIdStmt =
63
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_SWATCH_BY_OPTION_ID_AND_STORE_ID));
64
65
        // initialize the prepared statements
66
        $this->attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt =
67
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::ATTRIBUTE_OPTION_SWATCH_BY_ENTITY_TYPE_ID_AND_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE_AND_TYPE));
68
    }
69
70
    /**
71
     * Load's and return's the EAV attribute option swatch with the passed option ID and store ID
72
     *
73
     * @param string  $optionId The option ID of the attribute option swatch to load
74
     * @param integer $storeId  The store ID of the attribute option swatch to load
75
     *
76
     * @return array The EAV attribute option swatch
77
     */
78
    public function findOneByOptionIdAndStoreId($optionId, $storeId)
79
    {
80
81
        // the parameters of the EAV attribute option to load
82
        $params = array(
83
            MemberNames::OPTION_ID => $optionId,
84
            MemberNames::STORE_ID  => $storeId,
85
        );
86
87
        // load and return the EAV attribute option swatch with the passed parameters
88
        $this->attributeOptionSwatchByOptionIdAndStoreIdStmt->execute($params);
89
        return $this->attributeOptionSwatchByOptionIdAndStoreIdStmt->fetch(\PDO::FETCH_ASSOC);
90
    }
91
92
    /**
93
     * Load's and return's the EAV attribute option swatch with the passed entity type ID, code, store ID, value and type.
94
     *
95
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load the option swatch for
96
     * @param string  $attributeCode The code of the EAV attribute option swatch to load
97
     * @param integer $storeId       The store ID of the attribute option swatch to load
98
     * @param string  $value         The value of the attribute option swatch to load
99
     * @param string  $type          The type of the attribute option swatch to load
100
     *
101
     * @return array The EAV attribute option swatch
102
     */
103 View Code Duplication
    public function findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId, $attributeCode, $storeId, $value, $type)
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::ENTITY_TYPE_ID => $entityTypeId,
109
            MemberNames::ATTRIBUTE_CODE => $attributeCode,
110
            MemberNames::STORE_ID       => $storeId,
111
            MemberNames::VALUE          => $value,
112
            MemberNames::TYPE           => $type
113
        );
114
115
        // load and return the EAV attribute option swatch with the passed parameters
116
        $this->attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt->execute($params);
117
        return $this->attributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndTypeStmt->fetch(\PDO::FETCH_ASSOC);
118
    }
119
}
120