Skip to content

Commit a9b10b7

Browse files
swissspidyCopilot
andauthored
Add validation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3c67503 commit a9b10b7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/cli/Table.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,16 @@ public function setFooters(array $footers) {
213213
* @param array $alignments An array of strings containing column alignments.
214214
*/
215215
public function setAlignments(array $alignments) {
216+
$validAlignments = array(Column::ALIGN_LEFT, Column::ALIGN_RIGHT, Column::ALIGN_CENTER);
217+
foreach ($alignments as $column => $alignment) {
218+
if (!in_array($alignment, $validAlignments, true)) {
219+
throw new \InvalidArgumentException("Invalid alignment value '$alignment' for column '$column'.");
220+
}
221+
if (!in_array($column, $this->_headers, true)) {
222+
throw new \InvalidArgumentException("Column '$column' does not exist in table headers.");
223+
}
224+
}
216225
$this->_alignments = $alignments;
217-
//TODO: Implement error if alignment is not valid and field is not valid
218226
}
219227

220228
/**

0 commit comments

Comments
 (0)