Passed
Push — master ( 552132...489160 )
by
unknown
03:54
created

loadCustomerByWebsiteIdAndIncrementId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Repositories\CustomerRepository
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
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Repositories;
16
17
use TechDivision\Import\Customer\Utils\MemberNames;
18
use TechDivision\Import\Customer\Utils\SqlStatementKeys;
19
use TechDivision\Import\Dbal\Collection\Repositories\AbstractRepository;
20
21
/**
22
 * Repository implementation to load customer 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
28
 * @link      http://www.techdivision.com
29
 */
30
class CustomerRepository extends AbstractRepository implements CustomerRepositoryInterface
31
{
32
33
    /**
34
     * The prepared statement to load a customer with the passed entity ID.
35
     *
36
     * @var \PDOStatement
37
     */
38
    protected $customerStmt;
39
40
    /**
41
     * The prepared statement to load a customer with the passed email and website ID.
42
     *
43
     * @var \PDOStatement
44
     */
45
    protected $customerByEmailAndWebsiteIdStmt;
46
47
    /**
48
     * The prepared statement to load a customer with the passed email and website ID.
49
     *
50
     * @var \PDOStatement
51
     */
52
    protected $customerByWebsiteIdAndIncrementIdStmt;
53
54
    /**
55
     * The prepared statement to load the existing customers.
56
     *
57
     * @var \PDOStatement
58
     */
59
    protected $customersStmt;
60
61
    /**
62
     * Initializes the repository's prepared statements.
63
     *
64
     * @return void
65
     */
66
    public function init()
67
    {
68
69
        // initialize the prepared statements
70
        $this->customerStmt =
71
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER));
72
        $this->customerByEmailAndWebsiteIdStmt =
73
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_BY_EMAIL_AND_WEBSITE_ID));
74
        $this->customerByWebsiteIdAndIncrementIdStmt =
75
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_BY_WEBSITE_ID_AND_INCREMET_ID));
76
        $this->customersStmt =
77
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMERS));
78
    }
79
80
    /**
81
     * Return's the available customers.
82
     *
83
     * @return array The available customers
84
     */
85
    public function findAll()
86
    {
87
        // load and return the available customers
88
        $this->customersStmt->execute();
89
        return $this->customersStmt->fetchAll(\PDO::FETCH_ASSOC);
90
    }
91
92
    /**
93
     * Return's the customer with the passed entity ID.
94
     *
95
     * @param integer $id The entity ID of the customer to return
96
     *
97
     * @return array|null The customer
98
     */
99
    public function load($id)
100
    {
101
102
        // if not, try to load the customer with the passed entity ID
103
        $this->customerStmt->execute(array(MemberNames::ENTITY_ID => $id));
104
        return $this->customerStmt->fetch(\PDO::FETCH_ASSOC);
105
    }
106
107
    /**
108
     * Return's the customer with the passed email and website ID.
109
     *
110
     * @param string $email     The email of the customer to return
111
     * @param string $websiteId The website ID of the customer to return
112
     *
113
     * @return array|null The customer
114
     */
115
    public function findOneByEmailAndWebsiteId($email, $websiteId)
116
    {
117
118
        // initialize the params
119
        $params = array(
120
            MemberNames::EMAIL      => $email,
121
            MemberNames::WEBSITE_ID => $websiteId
122
        );
123
124
        // if not, try to load the customer with the passed email and website ID
125
        $this->customerByEmailAndWebsiteIdStmt->execute($params);
126
        return $this->customerByEmailAndWebsiteIdStmt->fetch(\PDO::FETCH_ASSOC);
127
    }
128
129
    /**
130
     * Return's the customer with the passed email, website ID and increment id.
131
     *
132
     * @param string $websiteId The website ID of the customer to return
133
     * @param string $increment_id The website ID of the customer to return
134
     *
135
     * @return array|null The customer
136
     */
137
    public function loadCustomerByWebsiteIdAndIncrementId($websiteId, $increment_id)
138
    {
139
140
        // initialize the params
141
        $params = array(
142
            MemberNames::WEBSITE_ID => $websiteId,
143
            MemberNames::INCREMENT_ID => $increment_id
144
        );
145
146
        // if not, try to load the customer with the passed email and website ID
147
        $this->customerByWebsiteIdAndIncrementIdStmt->execute($params);
148
        return $this->customerByWebsiteIdAndIncrementIdStmt->fetch(\PDO::FETCH_ASSOC);
149
    }
150
}
151