1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Utils\ColumnValuesUtil |
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 |
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 value 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 |
32
|
|
|
* @link http://www.techdivision.com |
33
|
|
|
*/ |
34
|
|
|
class ColumnValuesUtil implements ColumnValuesUtilInterface |
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 key => value pairs of the passed table. |
65
|
|
|
* |
66
|
|
|
* @param string $tableName The table name to return the list for |
67
|
|
|
* |
68
|
|
|
* @return string The concatenated list with the key => value pairs |
69
|
|
|
*/ |
70
|
1 |
|
public function getColumnValues($tableName) |
71
|
|
|
{ |
72
|
|
|
|
73
|
|
|
// initialize the array for the column key => value pairs |
74
|
1 |
|
$columnValues = array(); |
75
|
|
|
|
76
|
|
|
// load the column names from the loader |
77
|
1 |
|
$columnNames = $this->columnNameLoader->load($this->tablePrefixUtil->getPrefixedTableName($tableName)); |
|
|
|
|
78
|
|
|
|
79
|
|
|
// load and append the column key => value pairs to the array |
80
|
1 |
|
foreach ($columnNames as $columnName) { |
81
|
1 |
|
$columnValues[] = sprintf('%s=:%s', $columnName, $columnName); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
// implode and return the column values |
85
|
1 |
|
return implode(',', $columnValues); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Compiles the passed SQL statement. |
90
|
|
|
* |
91
|
|
|
* @param string $statement The SQL statement to compile |
92
|
|
|
* |
93
|
|
|
* @return string The compiled SQL statement |
94
|
|
|
*/ |
95
|
|
|
public function compile($statement) |
96
|
|
|
{ |
97
|
1 |
|
return preg_replace_callback(sprintf('/\$\{%s:(.*)\}/U', ColumnValuesUtilInterface::TOKEN), function (array $matches) { |
98
|
1 |
|
return $this->getColumnValues($matches[1]); |
99
|
1 |
|
}, $statement); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.