Skip to content

Commit e842497

Browse files
swissspidyCopilot
andauthored
Update lib/cli/Table.php
Co-authored-by: Copilot <[email protected]>
1 parent 69bd29f commit e842497

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/cli/Table.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,14 @@ public function setFooters(array $footers) {
218218
*/
219219
public function setAlignments(array $alignments) {
220220
$valid_alignments = array_flip( array( Column::ALIGN_LEFT, Column::ALIGN_RIGHT, Column::ALIGN_CENTER ) );
221+
$headers_map = ! empty( $this->_headers ) ? array_flip( $this->_headers ) : null;
221222
foreach ( $alignments as $column => $alignment ) {
222223
if ( ! isset( $valid_alignments[ $alignment ] ) ) {
223224
throw new \InvalidArgumentException( "Invalid alignment value '$alignment' for column '$column'." );
224225
}
225226
// Only validate column names if headers are already set
226-
if ( ! empty( $this->_headers ) ) {
227-
$headers_map = array_flip( $this->_headers );
228-
if ( ! isset( $headers_map[ $column ] ) ) {
229-
throw new \InvalidArgumentException( "Column '$column' does not exist in table headers." );
230-
}
227+
if ( $headers_map !== null && ! isset( $headers_map[ $column ] ) ) {
228+
throw new \InvalidArgumentException( "Column '$column' does not exist in table headers." );
231229
}
232230
}
233231
$this->_alignments = $alignments;

0 commit comments

Comments
 (0)