Skip to content

Commit ce1c246

Browse files
Merge pull request #99 from TheDragonCode/patch/table-view
Revert "Refactor `TableView` to improve separator handling with distinct header and footer methods
2 parents 4cc40af + ae1ad06 commit ce1c246

File tree

10 files changed

+99
-113
lines changed

10 files changed

+99
-113
lines changed

src/View/TableView.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function show(array $data): void
1919
$headers = $this->headers($data);
2020
$widths = $this->columnWidths($headers, $data);
2121

22-
$this->writeHeaderLine($widths);
22+
$this->writeLine($this->separator($widths));
2323
$this->writeLine($this->formatRow($headers, $widths));
2424
$this->writeLine($this->separator($widths));
2525

@@ -33,7 +33,7 @@ public function show(array $data): void
3333
$this->writeLine($this->formatRow(array_values($row), $widths));
3434
}
3535

36-
$this->writeFooterLine($widths);
36+
$this->writeLine($this->separator($widths));
3737
}
3838

3939
protected function headers(array $data): array
@@ -54,25 +54,11 @@ protected function columnWidths(array $headers, array $data): array
5454
return $widths;
5555
}
5656

57-
protected function writeHeaderLine(array $widths): void
58-
{
59-
$this->writeLine(
60-
$this->separator($widths, '', '', '')
61-
);
62-
}
63-
64-
protected function writeFooterLine(array $widths): void
65-
{
66-
$this->writeLine(
67-
$this->separator($widths, '', '', '')
68-
);
69-
}
70-
71-
protected function separator(array $widths, string $start = '', string $divider = '', string $end = ''): string
57+
protected function separator(array $widths): string
7258
{
73-
$parts = array_map(static fn (int $w) => str_repeat('', $w + 2), $widths);
59+
$parts = array_map(fn (int $w) => str_repeat('-', $w + 2), $widths);
7460

75-
return $start . implode($divider, $parts) . $end;
61+
return '+' . implode('+', $parts) . '+';
7662
}
7763

7864
protected function formatRow(array $values, array $widths): string
@@ -83,6 +69,6 @@ protected function formatRow(array $values, array $widths): string
8369
$cells[] = ' ' . mb_str_pad((string) $value, $widths[$i]) . ' ';
8470
}
8571

86-
return '' . implode('', $cells) . '';
72+
return '|' . implode('|', $cells) . '|';
8773
}
8874
}

tests/.pest/snapshots/Unit/Result/ToConsoleTest/compare.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬───────────────────────────────┬──────────────────────────────┐
6-
# 0 1
7-
├───────┼───────────────────────────────┼──────────────────────────────┤
8-
min 15.67890123 ms - 202 bytes 2.3456789 ms - 102 bytes
9-
max 112.78901234 ms - 209 bytes 9.75678901 ms - 109 bytes
10-
avg 53.02524845125 ms - 205 bytes 5.94290024625 ms - 105 bytes
11-
total 424.20198761 ms - 1.61 KB 47.54320197 ms - 844 bytes
12-
├───────┼───────────────────────────────┼──────────────────────────────┤
13-
order 2 1
14-
└───────┴───────────────────────────────┴──────────────────────────────┘
5+
+-------+-------------------------------+------------------------------+
6+
| # | 0 | 1 |
7+
+-------+-------------------------------+------------------------------+
8+
| min | 15.67890123 ms - 202 bytes | 2.3456789 ms - 102 bytes |
9+
| max | 112.78901234 ms - 209 bytes | 9.75678901 ms - 109 bytes |
10+
| avg | 53.02524845125 ms - 205 bytes | 5.94290024625 ms - 105 bytes |
11+
| total | 424.20198761 ms - 1.61 KB | 47.54320197 ms - 844 bytes |
12+
+-------+-------------------------------+------------------------------+
13+
| order | 2 | 1 |
14+
+-------+-------------------------------+------------------------------+

tests/.pest/snapshots/Unit/Result/ToConsoleTest/deviations.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌──────────────────┬───────────────────────────────┬──────────────────────────────┐
6-
# 0 1
7-
├──────────────────┼───────────────────────────────┼──────────────────────────────┤
8-
min 15.67890123 ms - 202 bytes 2.3456789 ms - 102 bytes
9-
max 112.78901234 ms - 209 bytes 9.75678901 ms - 109 bytes
10-
avg 53.02524845125 ms - 205 bytes 5.94290024625 ms - 105 bytes
11-
total 848.40397522 ms - 3.21 KB 95.08640394 ms - 1.65 KB
12-
├──────────────────┼───────────────────────────────┼──────────────────────────────┤
13-
order 2 1
14-
├──────────────────┼───────────────────────────────┼──────────────────────────────┤
15-
deviation time 0% 0%
16-
deviation memory 0% 0%
17-
└──────────────────┴───────────────────────────────┴──────────────────────────────┘
5+
+------------------+-------------------------------+------------------------------+
6+
| # | 0 | 1 |
7+
+------------------+-------------------------------+------------------------------+
8+
| min | 15.67890123 ms - 202 bytes | 2.3456789 ms - 102 bytes |
9+
| max | 112.78901234 ms - 209 bytes | 9.75678901 ms - 109 bytes |
10+
| avg | 53.02524845125 ms - 205 bytes | 5.94290024625 ms - 105 bytes |
11+
| total | 848.40397522 ms - 3.21 KB | 95.08640394 ms - 1.65 KB |
12+
+------------------+-------------------------------+------------------------------+
13+
| order | 2 | 1 |
14+
+------------------+-------------------------------+------------------------------+
15+
| deviation time | 0% | 0% |
16+
| deviation memory | 0% | 0% |
17+
+------------------+-------------------------------+------------------------------+

tests/.pest/snapshots/Unit/Round/RoundTest/default.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬───────────────────────────────┬──────────────────────────────┐
6-
# 0 1
7-
├───────┼───────────────────────────────┼──────────────────────────────┤
8-
min 15.67890123 ms - 202 bytes 2.3456789 ms - 102 bytes
9-
max 112.78901234 ms - 209 bytes 9.75678901 ms - 109 bytes
10-
avg 53.02524845125 ms - 205 bytes 5.94290024625 ms - 105 bytes
11-
total 424.20198761 ms - 1.61 KB 47.54320197 ms - 844 bytes
12-
├───────┼───────────────────────────────┼──────────────────────────────┤
13-
order 2 1
14-
└───────┴───────────────────────────────┴──────────────────────────────┘
5+
+-------+-------------------------------+------------------------------+
6+
| # | 0 | 1 |
7+
+-------+-------------------------------+------------------------------+
8+
| min | 15.67890123 ms - 202 bytes | 2.3456789 ms - 102 bytes |
9+
| max | 112.78901234 ms - 209 bytes | 9.75678901 ms - 109 bytes |
10+
| avg | 53.02524845125 ms - 205 bytes | 5.94290024625 ms - 105 bytes |
11+
| total | 424.20198761 ms - 1.61 KB | 47.54320197 ms - 844 bytes |
12+
+-------+-------------------------------+------------------------------+
13+
| order | 2 | 1 |
14+
+-------+-------------------------------+------------------------------+

tests/.pest/snapshots/Unit/Round/RoundTest/round_with_data_set___0__.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬────────────────────┬───────────────────┐
6-
# 0 1
7-
├───────┼────────────────────┼───────────────────┤
8-
min 16 ms - 202 bytes 2 ms - 102 bytes
9-
max 113 ms - 209 bytes 10 ms - 109 bytes
10-
avg 53 ms - 205 bytes 6 ms - 105 bytes
11-
total 424 ms - 1.61 KB 48 ms - 844 bytes
12-
├───────┼────────────────────┼───────────────────┤
13-
order 2 1
14-
└───────┴────────────────────┴───────────────────┘
5+
+-------+--------------------+-------------------+
6+
| # | 0 | 1 |
7+
+-------+--------------------+-------------------+
8+
| min | 16 ms - 202 bytes | 2 ms - 102 bytes |
9+
| max | 113 ms - 209 bytes | 10 ms - 109 bytes |
10+
| avg | 53 ms - 205 bytes | 6 ms - 105 bytes |
11+
| total | 424 ms - 1.61 KB | 48 ms - 844 bytes |
12+
+-------+--------------------+-------------------+
13+
| order | 2 | 1 |
14+
+-------+--------------------+-------------------+

tests/.pest/snapshots/Unit/Round/RoundTest/round_with_data_set___0____0_.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬────────────────────┬───────────────────┐
6-
# 0 1
7-
├───────┼────────────────────┼───────────────────┤
8-
min 16 ms - 202 bytes 2 ms - 102 bytes
9-
max 113 ms - 209 bytes 10 ms - 109 bytes
10-
avg 53 ms - 205 bytes 6 ms - 105 bytes
11-
total 424 ms - 1.61 KB 48 ms - 844 bytes
12-
├───────┼────────────────────┼───────────────────┤
13-
order 2 1
14-
└───────┴────────────────────┴───────────────────┘
5+
+-------+--------------------+-------------------+
6+
| # | 0 | 1 |
7+
+-------+--------------------+-------------------+
8+
| min | 16 ms - 202 bytes | 2 ms - 102 bytes |
9+
| max | 113 ms - 209 bytes | 10 ms - 109 bytes |
10+
| avg | 53 ms - 205 bytes | 6 ms - 105 bytes |
11+
| total | 424 ms - 1.61 KB | 48 ms - 844 bytes |
12+
+-------+--------------------+-------------------+
13+
| order | 2 | 1 |
14+
+-------+--------------------+-------------------+

tests/.pest/snapshots/Unit/Round/RoundTest/round_with_data_set___2__.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬───────────────────────┬──────────────────────┐
6-
# 0 1
7-
├───────┼───────────────────────┼──────────────────────┤
8-
min 15.68 ms - 202 bytes 2.35 ms - 102 bytes
9-
max 112.79 ms - 209 bytes 9.76 ms - 109 bytes
10-
avg 53.03 ms - 205 bytes 5.94 ms - 105 bytes
11-
total 424.2 ms - 1.61 KB 47.54 ms - 844 bytes
12-
├───────┼───────────────────────┼──────────────────────┤
13-
order 2 1
14-
└───────┴───────────────────────┴──────────────────────┘
5+
+-------+-----------------------+----------------------+
6+
| # | 0 | 1 |
7+
+-------+-----------------------+----------------------+
8+
| min | 15.68 ms - 202 bytes | 2.35 ms - 102 bytes |
9+
| max | 112.79 ms - 209 bytes | 9.76 ms - 109 bytes |
10+
| avg | 53.03 ms - 205 bytes | 5.94 ms - 105 bytes |
11+
| total | 424.2 ms - 1.61 KB | 47.54 ms - 844 bytes |
12+
+-------+-----------------------+----------------------+
13+
| order | 2 | 1 |
14+
+-------+-----------------------+----------------------+

tests/.pest/snapshots/Unit/Round/RoundTest/round_with_data_set___2____2_.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬───────────────────────┬──────────────────────┐
6-
# 0 1
7-
├───────┼───────────────────────┼──────────────────────┤
8-
min 15.68 ms - 202 bytes 2.35 ms - 102 bytes
9-
max 112.79 ms - 209 bytes 9.76 ms - 109 bytes
10-
avg 53.03 ms - 205 bytes 5.94 ms - 105 bytes
11-
total 424.2 ms - 1.61 KB 47.54 ms - 844 bytes
12-
├───────┼───────────────────────┼──────────────────────┤
13-
order 2 1
14-
└───────┴───────────────────────┴──────────────────────┘
5+
+-------+-----------------------+----------------------+
6+
| # | 0 | 1 |
7+
+-------+-----------------------+----------------------+
8+
| min | 15.68 ms - 202 bytes | 2.35 ms - 102 bytes |
9+
| max | 112.79 ms - 209 bytes | 9.76 ms - 109 bytes |
10+
| avg | 53.03 ms - 205 bytes | 5.94 ms - 105 bytes |
11+
| total | 424.2 ms - 1.61 KB | 47.54 ms - 844 bytes |
12+
+-------+-----------------------+----------------------+
13+
| order | 2 | 1 |
14+
+-------+-----------------------+----------------------+

tests/.pest/snapshots/Unit/Round/RoundTest/round_with_data_set___5__.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
33

44

5-
┌───────┬──────────────────────────┬────────────────────────┐
6-
# 0 1
7-
├───────┼──────────────────────────┼────────────────────────┤
8-
min 15.6789 ms - 202 bytes 2.34568 ms - 102 bytes
9-
max 112.78901 ms - 209 bytes 9.75679 ms - 109 bytes
10-
avg 53.02525 ms - 205 bytes 5.9429 ms - 105 bytes
11-
total 424.20199 ms - 1.61 KB 47.5432 ms - 844 bytes
12-
├───────┼──────────────────────────┼────────────────────────┤
13-
order 2 1
14-
└───────┴──────────────────────────┴────────────────────────┘
5+
+-------+--------------------------+------------------------+
6+
| # | 0 | 1 |
7+
+-------+--------------------------+------------------------+
8+
| min | 15.6789 ms - 202 bytes | 2.34568 ms - 102 bytes |
9+
| max | 112.78901 ms - 209 bytes | 9.75679 ms - 109 bytes |
10+
| avg | 53.02525 ms - 205 bytes | 5.9429 ms - 105 bytes |
11+
| total | 424.20199 ms - 1.61 KB | 47.5432 ms - 844 bytes |
12+
+-------+--------------------------+------------------------+
13+
| order | 2 | 1 |
14+
+-------+--------------------------+------------------------+

0 commit comments

Comments
 (0)