@@ -41,17 +41,17 @@ class Table
41
41
/**
42
42
* Table headers.
43
43
*/
44
- private $ headers = array () ;
44
+ private $ headers = [] ;
45
45
46
46
/**
47
47
* Table rows.
48
48
*/
49
- private $ rows = array () ;
49
+ private $ rows = [] ;
50
50
51
51
/**
52
52
* Column widths cache.
53
53
*/
54
- private $ effectiveColumnWidths = array () ;
54
+ private $ effectiveColumnWidths = [] ;
55
55
56
56
/**
57
57
* Number of columns cache.
@@ -73,15 +73,15 @@ class Table
73
73
/**
74
74
* @var array
75
75
*/
76
- private $ columnStyles = array () ;
76
+ private $ columnStyles = [] ;
77
77
78
78
/**
79
79
* User set column widths.
80
80
*
81
81
* @var array
82
82
*/
83
- private $ columnWidths = array () ;
84
- private $ columnMaxWidths = array () ;
83
+ private $ columnWidths = [] ;
84
+ private $ columnMaxWidths = [] ;
85
85
86
86
private static $ styles ;
87
87
@@ -212,7 +212,7 @@ public function setColumnWidth($columnIndex, $width)
212
212
*/
213
213
public function setColumnWidths (array $ widths )
214
214
{
215
- $ this ->columnWidths = array () ;
215
+ $ this ->columnWidths = [] ;
216
216
foreach ($ widths as $ index => $ width ) {
217
217
$ this ->setColumnWidth ($ index , $ width );
218
218
}
@@ -243,7 +243,7 @@ public function setHeaders(array $headers)
243
243
{
244
244
$ headers = array_values ($ headers );
245
245
if (!empty ($ headers ) && !\is_array ($ headers [0 ])) {
246
- $ headers = array ( $ headers) ;
246
+ $ headers = [ $ headers] ;
247
247
}
248
248
249
249
$ this ->headers = $ headers ;
@@ -253,7 +253,7 @@ public function setHeaders(array $headers)
253
253
254
254
public function setRows (array $ rows )
255
255
{
256
- $ this ->rows = array () ;
256
+ $ this ->rows = [] ;
257
257
258
258
return $ this ->addRows ($ rows );
259
259
}
@@ -339,7 +339,7 @@ public function setFooterTitle(?string $title): self
339
339
*/
340
340
public function render ()
341
341
{
342
- $ rows = array_merge ($ this ->headers , array ( $ divider = new TableSeparator ()) , $ this ->rows );
342
+ $ rows = array_merge ($ this ->headers , [ $ divider = new TableSeparator ()] , $ this ->rows );
343
343
$ this ->calculateNumberOfColumns ($ rows );
344
344
345
345
$ rows = $ this ->buildTableRows ($ rows );
@@ -400,13 +400,13 @@ private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $tit
400
400
401
401
$ crossings = $ this ->style ->getCrossingChars ();
402
402
if (self ::SEPARATOR_MID === $ type ) {
403
- list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = array ( $ borders [2 ], $ crossings [8 ], $ crossings [0 ], $ crossings [4 ]) ;
403
+ list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = [ $ borders [2 ], $ crossings [8 ], $ crossings [0 ], $ crossings [4 ]] ;
404
404
} elseif (self ::SEPARATOR_TOP === $ type ) {
405
- list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = array ( $ borders [0 ], $ crossings [1 ], $ crossings [2 ], $ crossings [3 ]) ;
405
+ list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = [ $ borders [0 ], $ crossings [1 ], $ crossings [2 ], $ crossings [3 ]] ;
406
406
} elseif (self ::SEPARATOR_TOP_BOTTOM === $ type ) {
407
- list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = array ( $ borders [0 ], $ crossings [9 ], $ crossings [10 ], $ crossings [11 ]) ;
407
+ list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = [ $ borders [0 ], $ crossings [9 ], $ crossings [10 ], $ crossings [11 ]] ;
408
408
} else {
409
- list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = array ( $ borders [0 ], $ crossings [7 ], $ crossings [6 ], $ crossings [5 ]) ;
409
+ list ($ horizontal , $ leftChar , $ midChar , $ rightChar ) = [ $ borders [0 ], $ crossings [7 ], $ crossings [6 ], $ crossings [5 ]] ;
410
410
}
411
411
412
412
$ markup = $ leftChar ;
@@ -500,7 +500,7 @@ private function renderCell(array $row, int $column, string $cellFormat)
500
500
*/
501
501
private function calculateNumberOfColumns ($ rows )
502
502
{
503
- $ columns = array ( 0 ) ;
503
+ $ columns = [ 0 ] ;
504
504
foreach ($ rows as $ row ) {
505
505
if ($ row instanceof TableSeparator) {
506
506
continue ;
@@ -516,7 +516,7 @@ private function buildTableRows($rows)
516
516
{
517
517
/** @var WrappableOutputFormatterInterface $formatter */
518
518
$ formatter = $ this ->output ->getFormatter ();
519
- $ unmergedRows = array () ;
519
+ $ unmergedRows = [] ;
520
520
for ($ rowKey = 0 ; $ rowKey < \count ($ rows ); ++$ rowKey ) {
521
521
$ rows = $ this ->fillNextRows ($ rows , $ rowKey );
522
522
@@ -531,7 +531,7 @@ private function buildTableRows($rows)
531
531
$ lines = explode ("\n" , str_replace ("\n" , "<fg=default;bg=default> \n</> " , $ cell ));
532
532
foreach ($ lines as $ lineKey => $ line ) {
533
533
if ($ cell instanceof TableCell) {
534
- $ line = new TableCell ($ line , array ( 'colspan ' => $ cell ->getColspan ()) );
534
+ $ line = new TableCell ($ line , [ 'colspan ' => $ cell ->getColspan ()] );
535
535
}
536
536
if (0 === $ lineKey ) {
537
537
$ rows [$ rowKey ][$ column ] = $ line ;
@@ -557,7 +557,7 @@ private function buildTableRows($rows)
557
557
558
558
private function calculateRowCount (): int
559
559
{
560
- $ numberOfRows = \count (iterator_to_array ($ this ->buildTableRows (array_merge ($ this ->headers , array ( new TableSeparator ()) , $ this ->rows ))));
560
+ $ numberOfRows = \count (iterator_to_array ($ this ->buildTableRows (array_merge ($ this ->headers , [ new TableSeparator ()] , $ this ->rows ))));
561
561
562
562
if ($ this ->headers ) {
563
563
++$ numberOfRows ; // Add row for header separator
@@ -575,27 +575,27 @@ private function calculateRowCount(): int
575
575
*/
576
576
private function fillNextRows (array $ rows , int $ line ): array
577
577
{
578
- $ unmergedRows = array () ;
578
+ $ unmergedRows = [] ;
579
579
foreach ($ rows [$ line ] as $ column => $ cell ) {
580
580
if (null !== $ cell && !$ cell instanceof TableCell && !is_scalar ($ cell ) && !(\is_object ($ cell ) && method_exists ($ cell , '__toString ' ))) {
581
581
throw new InvalidArgumentException (sprintf ('A cell must be a TableCell, a scalar or an object implementing __toString, %s given. ' , \gettype ($ cell )));
582
582
}
583
583
if ($ cell instanceof TableCell && $ cell ->getRowspan () > 1 ) {
584
584
$ nbLines = $ cell ->getRowspan () - 1 ;
585
- $ lines = array ( $ cell) ;
585
+ $ lines = [ $ cell] ;
586
586
if (strstr ($ cell , "\n" )) {
587
587
$ lines = explode ("\n" , str_replace ("\n" , "<fg=default;bg=default> \n</> " , $ cell ));
588
588
$ nbLines = \count ($ lines ) > $ nbLines ? substr_count ($ cell , "\n" ) : $ nbLines ;
589
589
590
- $ rows [$ line ][$ column ] = new TableCell ($ lines [0 ], array ( 'colspan ' => $ cell ->getColspan ()) );
590
+ $ rows [$ line ][$ column ] = new TableCell ($ lines [0 ], [ 'colspan ' => $ cell ->getColspan ()] );
591
591
unset($ lines [0 ]);
592
592
}
593
593
594
594
// create a two dimensional array (rowspan x colspan)
595
- $ unmergedRows = array_replace_recursive (array_fill ($ line + 1 , $ nbLines , array () ), $ unmergedRows );
595
+ $ unmergedRows = array_replace_recursive (array_fill ($ line + 1 , $ nbLines , [] ), $ unmergedRows );
596
596
foreach ($ unmergedRows as $ unmergedRowKey => $ unmergedRow ) {
597
597
$ value = isset ($ lines [$ unmergedRowKey - $ line ]) ? $ lines [$ unmergedRowKey - $ line ] : '' ;
598
- $ unmergedRows [$ unmergedRowKey ][$ column ] = new TableCell ($ value , array ( 'colspan ' => $ cell ->getColspan ()) );
598
+ $ unmergedRows [$ unmergedRowKey ][$ column ] = new TableCell ($ value , [ 'colspan ' => $ cell ->getColspan ()] );
599
599
if ($ nbLines === $ unmergedRowKey - $ line ) {
600
600
break ;
601
601
}
@@ -608,7 +608,7 @@ private function fillNextRows(array $rows, int $line): array
608
608
if (isset ($ rows [$ unmergedRowKey ]) && \is_array ($ rows [$ unmergedRowKey ]) && ($ this ->getNumberOfColumns ($ rows [$ unmergedRowKey ]) + $ this ->getNumberOfColumns ($ unmergedRows [$ unmergedRowKey ]) <= $ this ->numberOfColumns )) {
609
609
foreach ($ unmergedRow as $ cellKey => $ cell ) {
610
610
// insert cell into row at cellKey position
611
- array_splice ($ rows [$ unmergedRowKey ], $ cellKey , 0 , array ( $ cell) );
611
+ array_splice ($ rows [$ unmergedRowKey ], $ cellKey , 0 , [ $ cell] );
612
612
}
613
613
} else {
614
614
$ row = $ this ->copyRow ($ rows , $ unmergedRowKey - 1 );
@@ -617,7 +617,7 @@ private function fillNextRows(array $rows, int $line): array
617
617
$ row [$ column ] = $ unmergedRow [$ column ];
618
618
}
619
619
}
620
- array_splice ($ rows , $ unmergedRowKey , 0 , array ( $ row) );
620
+ array_splice ($ rows , $ unmergedRowKey , 0 , [ $ row] );
621
621
}
622
622
}
623
623
@@ -629,7 +629,7 @@ private function fillNextRows(array $rows, int $line): array
629
629
*/
630
630
private function fillCells ($ row )
631
631
{
632
- $ newRow = array () ;
632
+ $ newRow = [] ;
633
633
foreach ($ row as $ column => $ cell ) {
634
634
$ newRow [] = $ cell ;
635
635
if ($ cell instanceof TableCell && $ cell ->getColspan () > 1 ) {
@@ -649,7 +649,7 @@ private function copyRow(array $rows, int $line): array
649
649
foreach ($ row as $ cellKey => $ cellValue ) {
650
650
$ row [$ cellKey ] = '' ;
651
651
if ($ cellValue instanceof TableCell) {
652
- $ row [$ cellKey ] = new TableCell ('' , array ( 'colspan ' => $ cellValue ->getColspan ()) );
652
+ $ row [$ cellKey ] = new TableCell ('' , [ 'colspan ' => $ cellValue ->getColspan ()] );
653
653
}
654
654
}
655
655
@@ -691,7 +691,7 @@ private function getRowColumns(array $row): array
691
691
private function calculateColumnsWidth (iterable $ rows )
692
692
{
693
693
for ($ column = 0 ; $ column < $ this ->numberOfColumns ; ++$ column ) {
694
- $ lengths = array () ;
694
+ $ lengths = [] ;
695
695
foreach ($ rows as $ row ) {
696
696
if ($ row instanceof TableSeparator) {
697
697
continue ;
@@ -742,7 +742,7 @@ private function getCellWidth(array $row, int $column): int
742
742
*/
743
743
private function cleanup ()
744
744
{
745
- $ this ->effectiveColumnWidths = array () ;
745
+ $ this ->effectiveColumnWidths = [] ;
746
746
$ this ->numberOfColumns = null ;
747
747
}
748
748
@@ -783,14 +783,14 @@ private static function initStyles()
783
783
->setCrossingChars ('┼ ' , '╔ ' , '╤ ' , '╗ ' , '╢ ' , '╝ ' , '╧ ' , '╚ ' , '╟ ' , '╠ ' , '╪ ' , '╣ ' )
784
784
;
785
785
786
- return array (
786
+ return [
787
787
'default ' => new TableStyle (),
788
788
'borderless ' => $ borderless ,
789
789
'compact ' => $ compact ,
790
790
'symfony-style-guide ' => $ styleGuide ,
791
791
'box ' => $ box ,
792
792
'box-double ' => $ boxDouble ,
793
- ) ;
793
+ ] ;
794
794
}
795
795
796
796
private function resolveStyle ($ name )
0 commit comments