Passed
Push — master ( feb03b...b59be3 )
by
unknown
11:32 queued 07:44
created

CustomerAddressRepository::loadByIncrementId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Repositories\CustomerAddressRepository
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-address
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Address\Repositories;
16
17
use TechDivision\Import\Customer\Address\Utils\MemberNames;
18
use TechDivision\Import\Customer\Address\Utils\SqlStatementKeys;
19
use TechDivision\Import\Dbal\Collection\Repositories\AbstractRepository;
20
21
/**
22
 * Repository implementation to load customer address data.
23
 *
24
 * @author    Tim Wagner <[email protected]>
25
 * @copyright 2018 TechDivision GmbH <[email protected]>
26
 * @license   https://opensource.org/licenses/MIT
27
 * @link      https://github.com/techdivision/import-customer-address
28
 * @link      http://www.techdivision.com
29
 */
30
class CustomerAddressRepository extends AbstractRepository implements CustomerAddressRepositoryInterface
31
{
32
33
    /**
34
     * The prepared statement to load a customer address with the passed entity ID.
35
     *
36
     * @var \PDOStatement
37
     */
38
    protected $customerAddressStmt;
39
40
    /**
41
     * The prepared statement to load the existing customer addresses.
42
     *
43
     * @var \PDOStatement
44
     */
45
    protected $customerAddressesStmt;
46
47
    /**
48
     * The prepared statement to load a customer address with the passed increment ID.
49
     *
50
     * @var \PDOStatement
51
     */
52
    protected $customerAddressIncrementIdStmt;
53
54
    /**
55
     * Initializes the repository's prepared statements.
56
     *
57
     * @return void
58
     */
59
    public function init()
60
    {
61
62
        // initialize the prepared statements
63
        $this->customerAddressStmt =
64
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESS));
65
        $this->customerAddressesStmt =
66
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESSES));
67
        $this->customerAddressIncrementIdStmt =
68
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESS_INCREMENT_ID));
69
    }
70
71
    /**
72
     * Return's the available customer addresses.
73
     *
74
     * @return array The available customer addresses
75
     */
76
    public function findAll()
77
    {
78
        // load and return the available customers
79
        $this->customerAddressesStmt->execute();
80
        return $this->customerAddressesStmt->fetchAll(\PDO::FETCH_ASSOC);
81
    }
82
83
    /**
84
     * Return's the customer address with the passed entity ID.
85
     *
86
     * @param integer $id The entity ID of the customer address to return
87
     *
88
     * @return array|null The customer
89
     */
90
    public function load($id)
91
    {
92
93
        // if not, try to load the customer with the passed entity ID
94
        $this->customerAddressStmt->execute(array(MemberNames::ENTITY_ID => $id));
95
        return $this->customerAddressStmt->fetch(\PDO::FETCH_ASSOC);
96
    }
97
98
    /**
99
     * Return's the customer address with the passed increment ID.
100
     *
101
     * @param string|int $icrementId The increment ID of the customer address to return
102
     *
103
     * @return array|null The customer
104
     */
105
    public function loadByIncrementId($icrementId)
106
    {
107
        // if not, try to load the customer with the passed Increment ID
108
        $this->customerAddressIncrementIdStmt->execute(array(MemberNames::INCREMENT_ID => $icrementId));
109
        return $this->customerAddressIncrementIdStmt->fetch(\PDO::FETCH_ASSOC);
110
    }
111
}
112