|
1
|
|
|
<?php |
|
2
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
3
|
|
|
namespace SetBased\Audit\MySql\Helper; |
|
4
|
|
|
|
|
5
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
6
|
|
|
use SetBased\Audit\MySql\Metadata\ColumnMetadata; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class for extended column type. |
|
10
|
|
|
*/ |
|
11
|
|
|
class ColumnTypeExtended |
|
12
|
|
|
{ |
|
13
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
14
|
|
|
/** |
|
15
|
|
|
* The metadata of the column. |
|
16
|
|
|
* |
|
17
|
|
|
* @var array[] |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $columnTypes = []; |
|
20
|
|
|
|
|
21
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
22
|
|
|
/** |
|
23
|
|
|
* Object constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param array[]|ColumnMetadata $columnTypes The metadata of the column. |
|
26
|
|
|
* @param null|string $typePrefix Prefix for column type name. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($columnTypes, $typePrefix) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->extendColumnTypes($columnTypes, $typePrefix); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
34
|
|
|
/** |
|
35
|
|
|
* Create array with all columns types. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array[]|ColumnMetadata $columnTypes The metadata of the column. |
|
38
|
|
|
* @param null|string $typePrefix Prefix for column type name. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function extendColumnTypes($columnTypes, $typePrefix) |
|
41
|
|
|
{ |
|
42
|
|
|
$columnTypes = $columnTypes->getProperties(); |
|
43
|
|
|
foreach ($columnTypes as $typeName => $typeValue) |
|
44
|
|
|
{ |
|
45
|
|
|
if ($typeName=='column_name') |
|
46
|
|
|
{ |
|
47
|
|
|
if (!isset($this->columnTypes['column_name'])) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->columnTypes[$typeName] = $typeValue; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
else |
|
53
|
|
|
{ |
|
54
|
|
|
$format = '%s_%s'; |
|
55
|
|
|
if (isset($typePrefix)) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->columnTypes[sprintf($format, $typePrefix, $typeName)] = $typeValue; |
|
58
|
|
|
} |
|
59
|
|
|
else |
|
60
|
|
|
{ |
|
61
|
|
|
$this->columnTypes[$typeName] = $typeValue; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
68
|
|
|
/** |
|
69
|
|
|
* Get columns type. |
|
70
|
|
|
* |
|
71
|
|
|
* @return \array[] |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
public function getTypes() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->columnTypes; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
82
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.