Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
ExportedColumn | |
100.00% |
7 / 7 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFormattedName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getColumnCreatingString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
convertColumnName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2020 (original work) Open Assessment Technologies SA; |
19 | * |
20 | */ |
21 | |
22 | namespace oat\tao\model\export\implementation\sql; |
23 | |
24 | /** |
25 | * Class ExportedColumn |
26 | * @package oat\tao\model\export\implementation\sql |
27 | */ |
28 | class ExportedColumn |
29 | { |
30 | public const TYPE_BOOLEAN = 'BOOLEAN'; |
31 | public const TYPE_INTEGER = 'INT'; |
32 | public const TYPE_DECIMAL = 'DECIMAL'; |
33 | public const TYPE_VARCHAR = 'VARCHAR(16000)'; |
34 | public const TYPE_TIMESTAMP = 'TIMESTAMP'; |
35 | |
36 | public const PREFIX = 'col_'; |
37 | |
38 | /** |
39 | * @var string $name |
40 | */ |
41 | private $name; |
42 | |
43 | /** |
44 | * @var string $type |
45 | */ |
46 | private $type; |
47 | |
48 | public function __construct(string $name, string $type) |
49 | { |
50 | $this->name = $name; |
51 | $this->type = $type; |
52 | } |
53 | |
54 | /** |
55 | * @return string |
56 | */ |
57 | public function getType(): string |
58 | { |
59 | return $this->type; |
60 | } |
61 | |
62 | /** |
63 | * @return string |
64 | */ |
65 | public function getName(): string |
66 | { |
67 | return $this->name; |
68 | } |
69 | |
70 | /** |
71 | * @return string |
72 | */ |
73 | public function getFormattedName(): string |
74 | { |
75 | return self::PREFIX . $this->convertColumnName($this->name); |
76 | } |
77 | |
78 | /** |
79 | * @return string |
80 | */ |
81 | public function getColumnCreatingString(): string |
82 | { |
83 | return $this->getFormattedName() . ' ' . $this->getType(); |
84 | } |
85 | |
86 | /** |
87 | * @param $columnName |
88 | * @return string |
89 | */ |
90 | private function convertColumnName($columnName): string |
91 | { |
92 | return preg_replace(['/(\s+|-)/', '/[^A-Za-z0-9_]/'], ['_', ''], strtolower($columnName)); |
93 | } |
94 | } |