Completed
Push — master ( c2b612...40d106 )
by Tim
9s
created

UrlRewriteRepository::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\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\Product\Repositories;
22
23
use TechDivision\Import\Repositories\AbstractRepository;
24
25
/**
26
 * Repository implementation to load URL rewrite 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 UrlRewriteRepository 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->urlRewritesStmt = $this->getConnection()
0 ignored issues
show
Bug introduced by
The property urlRewritesStmt 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
                                      ->prepare(
51
                                          $this->myStmt = $utilityClassName::URL_REWRITES_BY_ENTITY_TYPE_AND_ENTITY_ID
0 ignored issues
show
Bug introduced by
The property myStmt 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...
52
                                      );
53
    }
54
55
    /**
56
     * Return's an array with the URL rewrites for the passed entity type and ID.
57
     *
58
     * @param string  $entityType The entity type to load the URL rewrites for
59
     * @param integer $entityId   The entity ID to load the URL rewrites for
60
     *
61
     * @return array The URL rewrites
62
     */
63
    public function findAllByEntityTypeAndEntityId($entityType, $entityId)
64
    {
65
        // load and return the URL rewrites
66
        $this->urlRewritesStmt->execute(array($entityType, $entityId));
67
        return $this->urlRewritesStmt->fetchAll();
68
    }
69
}
70