Passed
Push — 16.x ( db1cc8...77f358 )
by
unknown
08:48 queued 38s
created

CustomerAddressRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 80
ccs 0
cts 17
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 6 1
A init() 0 10 1
A loadByIncrementId() 0 5 1
A findAll() 0 5 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Repositories\CustomerAddressRepository
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 2018 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-customer-address
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Customer\Address\Repositories;
22
23
use TechDivision\Import\Customer\Address\Utils\MemberNames;
24
use TechDivision\Import\Customer\Address\Utils\SqlStatementKeys;
25
use TechDivision\Import\Repositories\AbstractRepository;
26
27
/**
28
 * Repository implementation to load customer address data.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2018 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-customer-address
34
 * @link      http://www.techdivision.com
35
 */
36
class CustomerAddressRepository extends AbstractRepository implements CustomerAddressRepositoryInterface
0 ignored issues
show
Deprecated Code introduced by
The class TechDivision\Import\Repo...ries\AbstractRepository has been deprecated: Since 16.8.3 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

36
class CustomerAddressRepository extends /** @scrutinizer ignore-deprecated */ AbstractRepository implements CustomerAddressRepositoryInterface
Loading history...
37
{
38
39
    /**
40
     * The prepared statement to load a customer address with the passed entity ID.
41
     *
42
     * @var \PDOStatement
43
     */
44
    protected $customerAddressStmt;
45
46
    /**
47
     * The prepared statement to load the existing customer addresses.
48
     *
49
     * @var \PDOStatement
50
     */
51
    protected $customerAddressesStmt;
52
53
    /**
54
     * The prepared statement to load a customer address with the passed increment ID.
55
     *
56
     * @var \PDOStatement
57
     */
58
    protected $customerAddressIncrementIdStmt;
59
60
    /**
61
     * Initializes the repository's prepared statements.
62
     *
63
     * @return void
64
     */
65
    public function init()
66
    {
67
68
        // initialize the prepared statements
69
        $this->customerAddressStmt =
70
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESS));
71
        $this->customerAddressesStmt =
72
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESSES));
73
        $this->customerAddressIncrementIdStmt =
74
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESS_INCREMENT_ID));
75
    }
76
77
    /**
78
     * Return's the available customer addresses.
79
     *
80
     * @return array The available customer addresses
81
     */
82
    public function findAll()
83
    {
84
        // load and return the available customers
85
        $this->customerAddressesStmt->execute();
86
        return $this->customerAddressesStmt->fetchAll(\PDO::FETCH_ASSOC);
87
    }
88
89
    /**
90
     * Return's the customer address with the passed entity ID.
91
     *
92
     * @param integer $id The entity ID of the customer address to return
93
     *
94
     * @return array|null The customer
95
     */
96
    public function load($id)
97
    {
98
99
        // if not, try to load the customer with the passed entity ID
100
        $this->customerAddressStmt->execute(array(MemberNames::ENTITY_ID => $id));
101
        return $this->customerAddressStmt->fetch(\PDO::FETCH_ASSOC);
102
    } 
103
    
104
    /**
105
     * Return's the customer address with the passed increment ID.
106
     *
107
     * @param string|int $icrementId The increment ID of the customer address to return
108
     *
109
     * @return array|null The customer
110
     */
111
    public function loadByIncrementId($icrementId)
112
    {
113
        // if not, try to load the customer with the passed Increment ID
114
        $this->customerAddressIncrementIdStmt->execute(array(MemberNames::INCREMENT_ID => $icrementId));
115
        return $this->customerAddressIncrementIdStmt->fetch(\PDO::FETCH_ASSOC);
116
    }
117
}
118