Completed
Push — 15.x ( 39dd4d...e89609 )
by Tim
02:40
created

ColumnNamesUtil   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 55
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getColumnNames() 0 4 1
A compile() 0 6 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Utils\ColumnNamesUtil
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 2020 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-customer
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Utils;
22
23
use TechDivision\Import\Loaders\LoaderInterface;
24
25
/**
26
 * Utility class for dynamic column name handling.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2020 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-customer
32
 * @link      http://www.techdivision.com
33
 */
34
class ColumnNamesUtil implements ColumnNamesUtiInterface
35
{
36
37
    /**
38
     * The column name loader instance.
39
     *
40
     * @var \TechDivision\Import\Loaders\LoaderInterface
41
     */
42
    protected $columnNameLoader;
43
44
    /**
45
     * The table prefix utility instance.
46
     *
47
     * @var \TechDivision\Import\Utils\TablePrefixUtilInterface
48
     */
49
    protected $tablePrefixUtil;
50
51
    /**
52
     * Construct a new instance.
53
     *
54
     * @param \TechDivision\Import\Loaders\LoaderInterface        $columnNameLoader The column name loader instance
55
     * @param \TechDivision\Import\Utils\TablePrefixUtilInterface $tablePrefixUtil  The table prefix utility instance
56
     */
57 1
    public function __construct(LoaderInterface $columnNameLoader, TablePrefixUtilInterface $tablePrefixUtil)
58
    {
59 1
        $this->columnNameLoader = $columnNameLoader;
60 1
        $this->tablePrefixUtil = $tablePrefixUtil;
61 1
    }
62
63
    /**
64
     * Returns a concatenated list with column names of the passed table.
65
     *
66
     * @param string $tableName The table name to return the list for
67
     *
68
     * @return string The concatenated list of column names
69
     */
70 1
    public function getColumnNames($tableName)
71
    {
72 1
        return implode(',', $this->columnNameLoader->load($this->tablePrefixUtil->getPrefixedTableName($tableName)));
0 ignored issues
show
Unused Code introduced by
The call to LoaderInterface::load() has too many arguments starting with $this->tablePrefixUtil->...edTableName($tableName).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
73
    }
74
75
    /**
76
     * Compiles the passed SQL statement.
77
     *
78
     * @param string $statement The SQL statement to compile
79
     *
80
     * @return string The compiled SQL statement
81
     */
82
    public function compile($statement)
83
    {
84 1
        return preg_replace_callback(sprintf('/\$\{%s:(.*)\}/U', ColumnNamesUtiInterface::TOKEN), function (array $matches) {
85 1
            return $this->getColumnNames($matches[1]);
86 1
        }, $statement);
87
    }
88
}
89