Completed
Pull Request — master (#53)
by Tim
10:36
created

AbstractRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 81
ccs 0
cts 16
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A setUtilityClassName() 0 4 1
A getUtilityClassName() 0 4 1
A setConnection() 0 4 1
A getConnection() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\AbstractRepository
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
/**
24
 * An abstract respository implementation.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import
30
 * @link      http://www.techdivision.com
31
 */
32
abstract class AbstractRepository
33
{
34
35
    /**
36
     * The utility class name with the SQL statements to use.
37
     *
38
     * @var string
39
     */
40
    protected $utilityClassName;
41
42
    /**
43
     * The PDO connection instance.
44
     * .
45
     * @var \PDO
46
     */
47
    protected $connection;
48
49
    /**
50
     * Initialize the repository with the passed connection and utility class name.
51
     * .
52
     * @param \PDO|null   $connection       The PDO connection instance
53
     * @param string|null $utilityClassName The utility class name
54
     */
55
    public function __construct(\PDO $connection = null, $utilityClassName = null)
56
    {
57
58
        // if a connection has been passed, set it
59
        if ($connection) {
60
            $this->setConnection($connection);
61
        }
62
63
        // it a utility class name has been passed, set it
64
        if ($utilityClassName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $utilityClassName of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
65
            $this->setUtilityClassName($utilityClassName);
66
        }
67
    }
68
69
    /**
70
     * Set's the passed utility class with the SQL statements to use.
71
     *
72
     * @param string $utilityClassName The utility class name
73
     *
74
     * @return void
75
     */
76
    public function setUtilityClassName($utilityClassName)
77
    {
78
        $this->utilityClassName = $utilityClassName;
79
    }
80
81
    /**
82
     * Return's the utility class with the SQL statements to use.
83
     *
84
     * @return string The utility class name
85
     */
86
    public function getUtilityClassName()
87
    {
88
        return $this->utilityClassName;
89
    }
90
91
    /**
92
     * Set's the initialized PDO connection.
93
     * .
94
     * @param \PDO $connection The PDO connection instance
95
     *
96
     * @return void
97
     */
98
    public function setConnection(\PDO $connection)
99
    {
100
        $this->connection = $connection;
101
    }
102
103
    /**
104
     * Return's the initialized PDO connection.
105
     *
106
     * @return \PDO The initialized PDO connection
107
     */
108
    public function getConnection()
109
    {
110
        return $this->connection;
111
    }
112
}
113