InventorySourceRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 45
ccs 0
cts 10
cp 0
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 1
A findAll() 0 17 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Msi\Repositories\InventorySourceRepository
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-product-msi
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Product\Msi\Repositories;
16
17
use TechDivision\Import\Dbal\Collection\Repositories\AbstractRepository;
18
use TechDivision\Import\Product\Msi\Utils\MemberNames;
19
use TechDivision\Import\Product\Msi\Utils\SqlStatementKeys;
20
21
/**
22
 * Repository implementation to load MSI inventory source item 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-product-msi
28
 * @link      http://www.techdivision.com
29
 */
30
class InventorySourceRepository extends AbstractRepository implements InventorySourceRepositoryInterface
31
{
32
33
    /**
34
     * The prepared statement to load a inventory source item with the passed ID.
35
     *
36
     * @var \PDOStatement
37
     */
38
    protected $inventorySourcesStmt;
39
40
    /**
41
     * Initializes the repository's prepared statements.
42
     *
43
     * @return void
44
     */
45
    public function init()
46
    {
47
48
        // initialize the prepared statements
49
        $this->inventorySourcesStmt =
50
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::INVENTORY_SOURCES));
51
    }
52
53
    /**
54
     * Returns the available inventory sources.
55
     *
56
     * @return array The available inventory sources
57
     */
58
    public function findAll()
59
    {
60
61
        // initialize the array with the result
62
        $result = array();
63
64
        // load the inventory sources
65
        $this->inventorySourcesStmt->execute();
66
        $inventorySources = $this->inventorySourcesStmt->fetchAll(\PDO::FETCH_ASSOC);
67
68
        // add the inventory sources to the result using the source code as key
69
        foreach ($inventorySources as $inventorySource) {
70
            $result[$inventorySource[MemberNames::SOURCE_CODE]] = $inventorySource;
71
        }
72
73
        // returns the inventory sources
74
        return $result;
75
    }
76
}
77