comparison src/Replacer/TableReplacer.php @ 14:c969ed13c570 main-dev

Changes for various files
author luka
date Mon, 23 Sep 2024 20:35:14 -0400
parents 3426c7e91c24
children 19b7a8de0019
comparison
equal deleted inserted replaced
13:7ee152c22478 14:c969ed13c570
17 17
18 protected function get_attributes() 18 protected function get_attributes()
19 { 19 {
20 } 20 }
21 21
22 protected function getValuesForCreation() 22 protected function getValuesForCreation(): string
23 { 23 {
24 $insert = ''; 24 $insert = '';
25 foreach ($this->get_columns() as $column) { 25 foreach ($this->get_columns() as $column) {
26 $insert .= '$item->'.$column->getName().' = $validated["'.$column->getName().'"] ?? NULL;'."\n"; 26 $insert .= '$item->'.$column->getName().' = $validated["'.$column->getName().'"] ?? NULL;'."\n";
27 } 27 }
28 28
29 return $insert; 29 return $insert;
30 } 30 }
31 31
32 protected function getAttributes() 32 protected function getAttributes(): string
33 { 33 {
34 $insert = ''; 34 $insert = '';
35 foreach ($this->get_columns() as $column) { 35 foreach ($this->get_columns() as $column) {
36 $insert .= "'".$column->getName()."' => '',\n"; 36 $insert .= "'".$column->getName()."' => '',\n";
37 } 37 }
38 38
39 return $insert; 39 return $insert;
40 } 40 }
41 41
42 protected function getValuesForValidation() 42 protected function getValuesForValidation(): string
43 { 43 {
44 $insert = ''; 44 $insert = '';
45 foreach ($this->get_columns() as $column) { 45 foreach ($this->get_columns() as $column) {
46 $insert .= "'".$column->getName()."' => 'nullable',\n"; 46 $insert .= "'".$column->getName()."' => 'nullable',\n";
47 } 47 }
67 { 67 {
68 $table_name = $this->getTableInput(); 68 $table_name = $this->getTableInput();
69 $replacements = [ 69 $replacements = [
70 '// {{ valuesForCreation }}' => self::getValuesForCreation(), 70 '// {{ valuesForCreation }}' => self::getValuesForCreation(),
71 '# {{ atributeInsertPoint }}' => self::getAttributes(), 71 '# {{ atributeInsertPoint }}' => self::getAttributes(),
72 '// {{ valuesForValidation }}' => self::getValuesForValidation(), 72 '// {{ valuesForValidation }}' => self::getValuesForValidation(),
73 ]; 73 ];
74 74
75 foreach ($replacements as $key => &$replacement) { 75 foreach ($replacements as $key => &$replacement) {
76 $replacement = $replacement."\n".$key; 76 $replacement = $replacement."\n".$key;
77 } 77 }
78 78