Completed
Push — master ( 313f20...c23fe9 )
by Tim
9s
created

AbstractSqlStatementRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 30
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 11 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Repositories\AbstractSqlStatementRepository
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
 * Abstract repository class for the SQL statements to use.
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 AbstractSqlStatementRepository implements SqlStatementRepositoryInterface
33
{
34
35
    /**
36
     * The initializes SQL statements.
37
     *
38
     * @var array
39
     */
40
    protected $preparedStatements = array();
41
42
    /**
43
     * Returns the SQL statement with the passed ID.
44
     *
45
     * @param string $id The ID of the SQL statement to return
46
     *
47
     * @return string The SQL statement
48
     * @throws \Exception Is thrown, if the SQL statement with the passed key cannot be found
49
     */
50 2
    public function load($id)
51
    {
52
53
        // try to find the SQL statement with the passed key
54 2
        if (isset($this->preparedStatements[$id])) {
55 1
            return $this->preparedStatements[$id];
56
        }
57
58
        // throw an exception if NOT available
59 1
        throw new \Exception(sprintf('Can\'t find SQL statement with ID %s', $id));
60
    }
61
}
62