Completed
Pull Request — master (#46)
by Tim
03:34
created

UrlRewriteRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 48
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 1
A findAllByEntityTypeAndEntityId() 0 13 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\UrlRewriteRepository
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\Repositories\AbstractRepository;
24
use TechDivision\Import\Utils\MemberNames;
25
26
/**
27
 * Repository implementation to load URL rewrite data.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class UrlRewriteRepository extends AbstractRepository
36
{
37
38
    /**
39
     * The prepared statement to load the existing URL rewrites.
40
     *
41
     * @var \PDOStatement
42
     */
43
    protected $urlRewritesStmt;
44
45
    /**
46
     * Initializes the repository's prepared statements.
47
     *
48
     * @return void
49
     */
50
    public function init()
51
    {
52
53
        // load the utility class name
54
        $utilityClassName = $this->getUtilityClassName();
55
56
        // initialize the prepared statements
57
        $this->urlRewritesStmt = $this->getConnection()
58
                                      ->prepare($utilityClassName::URL_REWRITES_BY_ENTITY_TYPE_AND_ENTITY_ID);
59
    }
60
61
    /**
62
     * Return's an array with the URL rewrites for the passed entity type and ID.
63
     *
64
     * @param string  $entityType The entity type to load the URL rewrites for
65
     * @param integer $entityId   The entity ID to load the URL rewrites for
66
     *
67
     * @return array The URL rewrites
68
     */
69
    public function findAllByEntityTypeAndEntityId($entityType, $entityId)
70
    {
71
72
        // initialize the params
73
        $params = array(
74
            MemberNames::ENTITY_TYPE => $entityType,
75
            MemberNames::ENTITY_ID   => $entityId
76
        );
77
78
        // load and return the URL rewrites
79
        $this->urlRewritesStmt->execute($params);
80
        return $this->urlRewritesStmt->fetchAll(\PDO::FETCH_ASSOC);
81
    }
82
}
83