Completed
Push — master ( e87cd3...bce31c )
by Tim
7s
created

StoreRepository::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 6
cp 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\StoreRepository
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 store 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
class StoreRepository extends AbstractRepository
35
{
36
37
    /**
38
     * Initializes the repository's prepared statements.
39
     *
40
     * @return void
41
     */
42
    public function init()
43
    {
44
45
        // load the utility class name
46
        $utilityClassName = $this->getUtilityClassName();
47
48
        // initialize the prepared statements
49
        $this->storesStmt = $this->getConnection()->prepare($utilityClassName::STORES);
0 ignored issues
show
Bug introduced by
The property storesStmt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
50
        $this->storeDefaultStmt = $this->getConnection()->prepare($utilityClassName::STORE_DEFAULT);
0 ignored issues
show
Bug introduced by
The property storeDefaultStmt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
    }
52
53
    /**
54
     * Return's an array with the available stores and their
55
     * store codes as keys.
56
     *
57
     * @return array The array with all available stores
58
     */
59
    public function findAll()
60
    {
61
62
        // initialize the array with the available stores
63
        $stores = array();
64
65
        // execute the prepared statement
66
        $this->storesStmt->execute();
67
68
        // fetch the stores and assemble them as array with the store code as key
69
        foreach ($this->storesStmt->fetchAll() as $store) {
70
            $stores[$store[MemberNames::CODE]] = $store;
71
        }
72
73
        // return the array with the stores
74
        return $stores;
75
    }
76
77
    /**
78
     * Return's the default store.
79
     *
80
     * @return array The default store
81
     */
82
    public function findOneByDefault()
83
    {
84
85
        // execute the prepared statement and return the default store
86
        $this->storeDefaultStmt->execute();
87
        return $this->storeDefaultStmt->fetch();
88
    }
89
}
90