StringInjector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 30.19 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 16
loc 53
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 16 16 2
A extract() 0 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * AppserverIo\Server\Configuration\Extension\StringInjector
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
 * This class will get create a string from a single-column DB table called "virtualHost"
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 StringInjector extends AbstractInjector
33
{
34
    /**
35
     * @var array $data The data collected from the DB
36
     */
37
    protected $data;
38
39
    /**
40
     * Delimiter for the extracted string
41
     *
42
     * @const string STRING_DELIMETER
43
     */
44
    const STRING_DELIMETER = ' ';
45
46
    /**
47
     * Will init the injector's datasource
48
     *
49
     * @return void
50
     */
51 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...
52
    {
53
        // Init data as an empty array
54
        $this->data = array();
55
56
        // Grab our DB resource
57
        $dbConnection = $this->getDbResource();
58
59
        // Build up the query
60
        $query = 'SELECT * FROM `virtualHost`';
61
62
        // Get the results and fill them into our data
63
        foreach ($dbConnection->query($query) as $row) {
64
            $this->data[] = $row[0];
65
        }
66
    }
67
68
    /**
69
     * We will return a string containing all data entries delimitered by the configured delimiter
70
     *
71
     * @return mixed
72
     */
73
    public function extract()
74
    {
75
        // Iterate over all entries and concatenate them
76
        $result = '';
77
        foreach ($this->data as $dataEntry) {
78
            $result .= $dataEntry . self::STRING_DELIMETER;
79
        }
80
81
        // Cut the last delimiter
82
        return substr($result, 0, strlen($result) - strlen(self::STRING_DELIMETER));
83
    }
84
}
85