33namespace PHPSemVerChecker \Reporter ;
44
55use PHPSemVerChecker \Registry \Registry ;
6+ use Symfony \Component \Console \Helper \Table ;
67use Symfony \Component \Console \Output \OutputInterface ;
78
89class Reporter
@@ -23,25 +24,29 @@ public function output(Registry $beforeRegistry, Registry $afterRegistry, Output
2324 $ output ->writeln ('Suggested semantic versioning change: ' . Registry::levelToString ($ suggestedChange ));
2425
2526 $ 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 ' );
3529
3630 $ 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+ }
3934
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 ' ]);
4044 foreach ([Registry::MAJOR , Registry::MINOR , Registry::PATCH , Registry::NONE ] as $ level ) {
41- $ differencesForLevel = $ differences [' function ' ][$ level ];
45+ $ differencesForLevel = $ differences [$ type ][$ level ];
4246 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 ' ] ]);
4448 }
4549 }
50+ $ table ->render ();
4651 }
4752}
0 commit comments