3
3
namespace PHPSemVerChecker \Reporter ;
4
4
5
5
use PHPSemVerChecker \Registry \Registry ;
6
+ use Symfony \Component \Console \Helper \Table ;
6
7
use Symfony \Component \Console \Output \OutputInterface ;
7
8
8
9
class Reporter
@@ -23,25 +24,29 @@ public function output(Registry $beforeRegistry, Registry $afterRegistry, Output
23
24
$ output ->writeln ('Suggested semantic versioning change: ' . Registry::levelToString ($ suggestedChange ));
24
25
25
26
$ output ->writeln ('' ); // line clear
26
- $ output ->writeln ('CLASS ' );
27
- $ output ->writeln ("LEVEL \tLOCATION \tREASON " );
28
-
29
- foreach ([Registry::MAJOR , Registry::MINOR , Registry::PATCH , Registry::NONE ] as $ level ) {
30
- $ differencesForLevel = $ differences ['class ' ][$ level ];
31
- foreach ($ differencesForLevel as $ difference ) {
32
- $ output ->writeln (Registry::levelToString ($ level ) . "\t" . $ difference ['location ' ] . "\t" . $ difference ['reason ' ]);
33
- }
34
- }
27
+ $ output ->writeln ('Class ' );
28
+ $ this ->outputTable ($ output , $ differences , 'class ' );
35
29
36
30
$ output ->writeln ('' ); // line clear
37
- $ output ->writeln ('FUNCTION ' );
38
- $ output ->writeln ("LEVEL \tLOCATION \tREASON " );
31
+ $ output ->writeln ('Function ' );
32
+ $ this ->outputTable ($ output , $ differences , 'function ' );
33
+ }
39
34
35
+ /**
36
+ * @param \Symfony\Component\Console\Output\OutputInterface $output
37
+ * @param array $differences
38
+ * @param string $type
39
+ */
40
+ protected function outputTable (OutputInterface $ output , array $ differences , $ type )
41
+ {
42
+ $ table = new Table ($ output );
43
+ $ table ->setHeaders (['Level ' , 'Location ' , 'Reason ' ]);
40
44
foreach ([Registry::MAJOR , Registry::MINOR , Registry::PATCH , Registry::NONE ] as $ level ) {
41
- $ differencesForLevel = $ differences [' function ' ][$ level ];
45
+ $ differencesForLevel = $ differences [$ type ][$ level ];
42
46
foreach ($ differencesForLevel as $ difference ) {
43
- $ output -> writeln ( Registry::levelToString ($ level ) . "\t" . $ difference ['location ' ] . "\t" . $ difference ['reason ' ]);
47
+ $ table -> addRow ([ Registry::levelToString ($ level ), $ difference ['location ' ], $ difference ['reason ' ] ]);
44
48
}
45
49
}
50
+ $ table ->render ();
46
51
}
47
52
}
0 commit comments