annotate src/Replacer/TableReplacer.php @ 39:b5c6ebd33547 ls_dev_2025_09

Improving the factories, tests, and requests
author Luka Sitas <sitas.luka.97@gmail.com>
date Thu, 25 Sep 2025 23:16:13 -0400
parents 8dd668020310
children 2cf26b593f4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
1 <?php
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
2
19
19b7a8de0019 updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents: 14
diff changeset
3 namespace Wizard\MagicForger\Replacer;
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
4
6
b46922d4a301 Update for psr compliance
luka
parents: 5
diff changeset
5 trait TableReplacer
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
6 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
7 protected ?array $columns = null;
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
8
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
9 protected array $columns_to_ignore = [
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
10 'id',
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
11 'created_at',
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
12 'updated_at',
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
13 'created_by',
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
14 'updated_by',
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
15 'deleted_at',
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
16 ];
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
17
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
18 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
19 * Retrieve columns for the current table.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
20 */
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
21 protected function get_columns(): array
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
22 {
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
23 if (is_null($this->columns)) {
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
24 $this->columns = $this->getTableColumns($this->getCurrentTable());
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
25 }
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
26
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
27 return $this->columns;
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
28 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
29
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
30 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
31 * Get a string representation of values for creation.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
32 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
33 protected function getValuesForCreation(): string
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
34 {
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
35 $insert = '';
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
36 foreach ($this->get_columns() as $column) {
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
37 $column_name = $column['name'];
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
38 $insert .= sprintf('$item->%s = $validated["%s"] ?? NULL;', $column_name, $column_name)."\n";
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
39 }
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
40
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
41 return $insert;
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
42 }
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
43
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
44 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
45 * Get a string representation of table attributes.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
46 */
31
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
47 protected function getCasts(): string
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
48 {
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
49 $insert = '';
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
50 foreach ($this->get_columns() as $column) {
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
51 if (in_array($column['name'], $this->columns_to_ignore)) {
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
52 continue;
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
53 }
39
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
54 $type = $column['type_name'];
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
55 // date
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
56 if (in_array($type, ['date'])) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
57 $insert .= sprintf("'%s' => 'date:Y-m-d',", $column['name'])."\n";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
58 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
59 // time
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
60 if (in_array($type, ['timestamp'])) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
61 $insert .= sprintf("'%s' => 'date:Y-m-d H:i',", $column['name'])."\n";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
62 }
31
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
63 }
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
64
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
65 return $insert;
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
66 }
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
67
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
68 /**
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
69 * Get a string representation of table attributes.
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
70 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
71 protected function getAttributes(): string
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
72 {
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
73 $insert = '';
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
74 foreach ($this->get_columns() as $column) {
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
75 if (in_array($column['name'], $this->columns_to_ignore)) {
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
76 continue;
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
77 }
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
78 $insert .= sprintf("'%s' => '',", $column['name'])."\n";
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
79 }
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
80
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
81 return $insert;
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
82 }
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
83
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
84 /**
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
85 * Get a string representation of table fillable columns.
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
86 */
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
87 protected function getFillable(): string
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
88 {
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
89 $insert = '';
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
90 foreach ($this->get_columns() as $column) {
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
91 if (in_array($column['name'], $this->columns_to_ignore)) {
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
92 continue;
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
93 }
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
94 $insert .= sprintf("'%s',", $column['name'])."\n";
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
95 }
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
96
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
97 return $insert;
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
98 }
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
99
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
100 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
101 * Get formatted validation rules for table columns.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
102 */
14
c969ed13c570 Changes for various files
luka
parents: 11
diff changeset
103 protected function getValuesForValidation(): string
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
104 {
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
105 $insert = '';
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
106 foreach ($this->get_columns() as $column) {
39
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
107 // Don't do validation on some of the basic columns
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
108 if (in_array($column['name'], $this->columns_to_ignore)) {
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
109 continue;
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
110 }
39
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
111
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
112 $options = [];
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
113
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
114 // Add default value checks if needed
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
115 if (is_null($column['default']) && ! $column['nullable']) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
116 $options[] = "'required'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
117 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
118 else {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
119 $options[] = "'nullable'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
120 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
121
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
122 // Determine the validations based on column type
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
123 $type = strtolower($column['type_name']);
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
124 $size = (preg_match('/\((\d+)\)/', $column['type'], $matches)) ? $matches[1] : null;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
125
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
126 switch ($type) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
127 case 'varchar':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
128 case 'char':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
129 $options[] = "'string'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
130
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
131 // Extract length if defined
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
132 if (! is_null($size)) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
133 $options[] = "'max:$size'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
134 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
135 break;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
136
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
137 case 'text':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
138 $options[] = "'string'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
139 break;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
140
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
141 case 'int':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
142 case 'tinyint':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
143 case 'smallint':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
144 case 'mediumint':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
145 case 'bigint':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
146 $options[] = "'integer'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
147 if (strpos($column['type'], 'unsigned') !== false) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
148 $options[] = "'min:0'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
149 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
150 if (! is_null($size)) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
151 $options[] = "'max_digits:".$size."'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
152 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
153 break;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
154
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
155 case 'decimal':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
156 case 'double':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
157 case 'float':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
158 $options[] = "'numeric'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
159 // Extract precision and scale if defined
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
160 if (preg_match('/\((\d+),(\d+)\)/', $column['type'], $matches)) {
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
161 $precision = $matches[1];
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
162 $scale = isset($matches[2]) ? ','.$matches[2] : '';
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
163
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
164 $options[] = "'decimal:$precision$scale'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
165 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
166 break;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
167
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
168 case 'boolean':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
169 $options[] = "'boolean'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
170 break;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
171
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
172 case 'date':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
173 case 'datetime':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
174 case 'timestamp':
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
175 $options[] = "'date'";
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
176 break;
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
177
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
178 // Add other types as needed
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
179 }
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
180
b5c6ebd33547 Improving the factories, tests, and requests
Luka Sitas <sitas.luka.97@gmail.com>
parents: 31
diff changeset
181 $insert .= sprintf("'%s' => [%s],\n", $column['name'], implode(',', $options));
11
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
182 }
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
183
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
184 return $insert;
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
185 }
3426c7e91c24 Modifying generaters and replacers
luka
parents: 7
diff changeset
186
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
187 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
188 * Apply insertions in the target template.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
189 */
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
190 public function apply_inserts(string $target): string
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
191 {
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
192 $inserts = $this->get_all_keywords($target);
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
193 $available_insertions = $this->get_available_inserts();
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
194
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
195 return str_replace(
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
196 array_keys($available_insertions),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
197 $available_insertions,
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
198 $target
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
199 );
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
200 }
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
201
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
202 /**
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
203 * Get available insertion points for the template.
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
204 */
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
205 public function get_available_inserts(): array
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
206 {
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
207 return [
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
208 '// {{ valuesForCreation }}' => $this->getValuesForCreation(),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
209 '# {{ attributeInsertPoint }}' => $this->getAttributes(),
31
8dd668020310 started converting too bootstrap, also better support for casts
Luka Sitas <sitas.luka.97@gmail.com>
parents: 23
diff changeset
210 '# {{ castInsertPoint }}' => $this->getCasts(),
23
827efbf4d73c Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents: 21
diff changeset
211 '# {{ fillableInsertPoint }}' => $this->getFillable(),
21
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
212 '// {{ valuesForValidation }}' => $this->getValuesForValidation(),
f0b0d014e448 Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents: 19
diff changeset
213 ];
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 6
diff changeset
214 }
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents:
diff changeset
215 }