Completed
Push — master ( f7ddb9...eb6557 )
by Tim
9s
created

EavAttributeGroupRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 74
loc 74
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 10 10 1
A load() 7 7 1
A findAllByAttributeSetId() 17 17 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\EavAttributeGroupRepository
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
 * Repository implementation to load EAV attribute group 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 View Code Duplication
class EavAttributeGroupRepository extends AbstractRepository
0 ignored issues
show
Duplication introduced by
This class 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...
35
{
36
37
    /**
38
     * The prepared statement to load a specific attribute group.
39
     *
40
     * @var \PDOStatement
41
     */
42
    protected $eavAttributeGroupStmt;
43
44
    /**
45
     * The prepared statement to load an attribute group for a specific attribute set ID.
46
     *
47
     * @var \PDOStatement
48
     */
49
    protected $eavAttributeGroupsByAttributeSetIdStmt;
50
51
    /**
52
     * Initializes the repository's prepared statements.
53
     *
54
     * @return void
55
     */
56
    public function init()
57
    {
58
59
        // load the utility class name
60
        $utilityClassName = $this->getUtilityClassName();
61
62
        // initialize the prepared statements
63
        $this->eavAttributeGroupStmt = $this->getConnection()->prepare($utilityClassName::EAV_ATTRIBUTE_GROUP);
64
        $this->eavAttributeGroupsByAttributeSetIdStmt = $this->getConnection()->prepare($utilityClassName::EAV_ATTRIBUTE_GROUPS_BY_ATTRIBUTE_SET_ID);
65
    }
66
67
    /**
68
     * Return's the EAV attribute group with the passed ID.
69
     *
70
     * @param integer $id The EAV attribute group ID
71
     *
72
     * @return array The EAV attribute group
73
     */
74
    public function load($id)
75
    {
76
77
        // execute the prepared statement and return the EAV attribute group with the passed ID
78
        $this->eavAttributeGroupStmt->execute(array($id));
79
        return $this->eavAttributeGroupStmt->fetch(\PDO::FETCH_ASSOC);
80
    }
81
82
    /**
83
     * Return's the attribute groups for the passed attribute set ID, whereas the array
84
     * is prepared with the attribute group names as keys.
85
     *
86
     * @param mixed $attributeSetId The EAV attribute set ID to return the attribute groups for
87
     *
88
     * @return array|boolean The EAV attribute groups for the passed attribute ID
89
     */
90
    public function findAllByAttributeSetId($attributeSetId)
91
    {
92
93
        // initialize the array for the EAV attribute sets
94
        $eavAttributeGroups = array();
95
96
        // load the attributes
97
        $this->eavAttributeGroupsByAttributeSetIdStmt->execute(array(MemberNames::ATTRIBUTE_SET_ID => $attributeSetId));
98
99
        // prepare the array with the attribute group names as keys
100
        foreach ($this->eavAttributeGroupsByAttributeSetIdStmt->fetchAll(\PDO::FETCH_ASSOC) as $eavAttributeGroup) {
101
            $eavAttributeGroups[$eavAttributeGroup[MemberNames::ATTRIBUTE_GROUP_NAME]] = $eavAttributeGroup;
102
        }
103
104
        // return the array with the EAV attribute groups
105
        return $eavAttributeGroups;
106
    }
107
}
108