|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: shawe [email protected] |
|
5
|
|
|
* Date: 26/05/18 |
|
6
|
|
|
* Time: 22:11 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace FacturaScriptsUtils\Console\Command\Common; |
|
10
|
|
|
|
|
11
|
|
|
use FacturaScripts\Core\Base\DataBase; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Trait TableInformation. |
|
15
|
|
|
* |
|
16
|
|
|
* @author Francesc Pineda Segarra <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
trait TableInformation |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Returns an array with tables. |
|
23
|
|
|
* |
|
24
|
|
|
* @param DataBase $dataBase |
|
25
|
|
|
* |
|
26
|
|
|
* @return array |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getTables(DataBase $dataBase): array |
|
29
|
|
|
{ |
|
30
|
|
|
return $dataBase->getTables(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Returns an array with the columns of a given table. |
|
35
|
|
|
* |
|
36
|
|
|
* @param DataBase $dataBase |
|
37
|
|
|
* @param string $tableName |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getItemsFromTable(DataBase $dataBase, string $tableName): array |
|
42
|
|
|
{ |
|
43
|
|
|
return $dataBase->getColumns($tableName); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns an array with the constraints of a table. |
|
48
|
|
|
* |
|
49
|
|
|
* @param DataBase $dataBase |
|
50
|
|
|
* @param string $tableName |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getConstraintFromTable(DataBase $dataBase, $tableName): array |
|
55
|
|
|
{ |
|
56
|
|
|
return $dataBase->getConstraints($tableName, true); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Convert type to XML/PHP type. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $type |
|
63
|
|
|
* @param string $usedOn |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function parseType($type = '', string $usedOn = ''): string |
|
68
|
|
|
{ |
|
69
|
|
|
switch ($usedOn) { |
|
70
|
|
|
case 'table': |
|
71
|
|
|
$type = str_replace('varchar', 'character varying', $type); |
|
72
|
|
|
$type = preg_replace('/^double$/', 'double precision', $type); |
|
73
|
|
|
$type = preg_replace('/^int\(\d+\)/', 'integer', $type); |
|
74
|
|
|
$type = preg_replace('/tinyint\(1\)/', 'boolean', $type); |
|
75
|
|
|
$type = preg_replace('/^timestamp$/', 'timestamp without time zone', $type); |
|
76
|
|
|
break; |
|
77
|
|
|
case 'php': |
|
78
|
|
|
$type = preg_replace('/^varchar\(\d+\)/', 'string', $type); |
|
79
|
|
|
$type = preg_replace('/^character varying\(\d+\)/', 'string', $type); |
|
80
|
|
|
$type = str_replace('text', 'string', $type); |
|
81
|
|
|
$type = str_replace('double precision', 'float', $type); |
|
82
|
|
|
$type = preg_replace('/^int\(\d+\)/', 'int', $type); |
|
83
|
|
|
$type = preg_replace('/tinyint\(1\)/', 'bool', $type); |
|
84
|
|
|
$type = preg_replace('/^timestamp$/', 'string', $type); |
|
85
|
|
|
$type = str_replace('date', 'string', $type); |
|
86
|
|
|
break; |
|
87
|
|
|
case 'view': |
|
88
|
|
|
$type = preg_replace('/^character varying\(\d+\)/', 'text', $type); |
|
89
|
|
|
$type = str_replace('double precision', 'number-decimal', $type); |
|
90
|
|
|
$type = str_replace('integer', 'number', $type); |
|
91
|
|
|
$type = str_replace('boolean', 'checkbox', $type); |
|
92
|
|
|
$type = preg_replace('/^timestamp$/', 'text', $type); |
|
93
|
|
|
$type = str_replace('time without time zone', 'text', $type); |
|
94
|
|
|
$type = str_replace('date', 'datepicker', $type); |
|
95
|
|
|
break; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $type; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths