ArrayInjector::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 6

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * AppserverIo\Server\Configuration\Extension\ArrayInjector
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    Bernhard Wick <[email protected]>
15
 * @copyright 2015 TechDivision GmbH - <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://www.github.com/appserver-io/server
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Server\Configuration\Extension;
22
23
/**
24
 * Will inject data in the form of an array of the structure "key" => "value" (DB must look accordingly)
25
 *
26
 * @author    Bernhard Wick <[email protected]>
27
 * @copyright 2015 TechDivision GmbH - <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://www.github.com/appserver-io/server
30
 * @link      http://www.appserver.io
31
 */
32
class ArrayInjector extends AbstractInjector
33
{
34
    /**
35
     * @var array $data The data collected from the DB
36
     */
37
    protected $data;
38
39
    /**
40
     * Will init the injector's datasource
41
     *
42
     * @return void
43
     */
44 View Code Duplication
    public function init()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        // Init data as an empty array
47
        $this->data = array();
48
49
        // Grab our DB resource
50
        $dbConnection = $this->getDbResource();
51
52
        // Build up the query
53
        $query = 'SELECT * FROM `rewrite`';
54
55
        // Get the results and fill them into our data
56
        foreach ($dbConnection->query($query, \PDO::FETCH_ASSOC) as $row) {
57
            $this->data[$row['key']] = $row['value'];
58
        }
59
    }
60
61
    /**
62
     * We will return a string containing all data entries delimetered by the configured delimeter
63
     *
64
     * @return mixed
65
     */
66
    public function extract()
67
    {
68
        return $this->data;
69
    }
70
}
71