@@ -8,10 +8,13 @@ class TextGrid
88{
99 private bool $ isCli ;
1010
11+ /** @var mixed[][] */
1112 protected array $ matrix ;
1213
14+ /** @var int[] */
1315 protected array $ rows ;
1416
17+ /** @var string[] */
1518 protected array $ columns ;
1619
1720 private string $ gridDisplay ;
@@ -22,6 +25,7 @@ class TextGrid
2225
2326 private bool $ columnHeaders = true ;
2427
28+ /** @param mixed[][] $matrix */
2529 public function __construct (array $ matrix , bool $ isCli = true , bool $ rowDividers = false , bool $ rowHeaders = true , bool $ columnHeaders = true )
2630 {
2731 $ this ->rows = array_keys ($ matrix );
@@ -63,6 +67,7 @@ public function render(): string
6367 return $ this ->gridDisplay ;
6468 }
6569
70+ /** @param int[] $columnWidths */
6671 private function renderRows (int $ maxRowLength , array $ columnWidths ): void
6772 {
6873 foreach ($ this ->matrix as $ row => $ rowData ) {
@@ -77,6 +82,10 @@ private function renderRows(int $maxRowLength, array $columnWidths): void
7782 }
7883 }
7984
85+ /**
86+ * @param mixed[] $rowData
87+ * @param int[] $columnWidths
88+ */
8089 private function renderCells (array $ rowData , array $ columnWidths ): void
8190 {
8291 foreach ($ rowData as $ column => $ cell ) {
@@ -87,6 +96,7 @@ private function renderCells(array $rowData, array $columnWidths): void
8796 }
8897 }
8998
99+ /** @param int[] $columnWidths */
90100 private function renderColumnHeader (int $ maxRowLength , array &$ columnWidths ): void
91101 {
92102 if (!$ this ->columnHeaders ) {
@@ -95,6 +105,7 @@ private function renderColumnHeader(int $maxRowLength, array &$columnWidths): vo
95105 return ;
96106 }
97107 foreach ($ this ->columns as $ column => $ reference ) {
108+ /** @var string $reference */
98109 $ columnWidths [$ column ] = max ($ columnWidths [$ column ], $ this ->strlen ($ reference ));
99110 }
100111 if ($ this ->rowHeaders ) {
@@ -109,13 +120,15 @@ private function renderColumnHeader(int $maxRowLength, array &$columnWidths): vo
109120 $ this ->gridDisplay .= str_repeat (' ' , $ maxRowLength + 2 );
110121 }
111122 foreach ($ this ->columns as $ column => $ reference ) {
123+ /** @var scalar $reference */
112124 $ this ->gridDisplay .= '| ' . str_pad ((string ) $ reference , $ columnWidths [$ column ] + 1 , ' ' );
113125 }
114126 $ this ->gridDisplay .= '| ' . PHP_EOL ;
115127
116128 $ this ->renderFooter ($ maxRowLength , $ columnWidths );
117129 }
118130
131+ /** @param int[] $columnWidths */
119132 private function renderFooter (int $ maxRowLength , array $ columnWidths ): void
120133 {
121134 if ($ this ->rowHeaders ) {
@@ -128,6 +141,7 @@ private function renderFooter(int $maxRowLength, array $columnWidths): void
128141 $ this ->gridDisplay .= '+ ' . PHP_EOL ;
129142 }
130143
144+ /** @return int[] */
131145 private function getColumnWidths (): array
132146 {
133147 $ columnCount = count ($ this ->matrix , COUNT_RECURSIVE ) / count ($ this ->matrix );
@@ -139,6 +153,7 @@ private function getColumnWidths(): array
139153 return $ columnWidths ;
140154 }
141155
156+ /** @param mixed[] $columnData */
142157 private function getColumnWidth (array $ columnData ): int
143158 {
144159 $ columnWidth = 0 ;
0 commit comments