@@ -25,13 +25,9 @@ class CognitiveMetricTextRenderer implements CognitiveMetricTextRendererInterfac
2525 private TableHeaderBuilder $ headerBuilder ;
2626
2727 public function __construct (
28- private readonly OutputInterface $ output ,
2928 private readonly ConfigService $ configService ,
3029 ) {
31- $ config = $ this ->configService ->getConfig ();
32- $ this ->formatter = new MetricFormatter ($ config );
33- $ this ->rowBuilder = new TableRowBuilder ($ this ->formatter , $ config );
34- $ this ->headerBuilder = new TableHeaderBuilder ($ config );
30+ // Don't initialize components here - they'll be created with current config when rendering
3531 }
3632
3733 private function metricExceedsThreshold (CognitiveMetrics $ metric , CognitiveConfig $ config ): bool
@@ -43,26 +39,33 @@ private function metricExceedsThreshold(CognitiveMetrics $metric, CognitiveConfi
4339
4440 /**
4541 * @param CognitiveMetricsCollection $metricsCollection
42+ * @param OutputInterface $output
4643 * @throws CognitiveAnalysisException
4744 */
48- public function render (CognitiveMetricsCollection $ metricsCollection ): void
45+ public function render (CognitiveMetricsCollection $ metricsCollection, OutputInterface $ output ): void
4946 {
5047 $ config = $ this ->configService ->getConfig ();
5148
49+ // Recreate components with current configuration
50+ $ this ->formatter = new MetricFormatter ($ config );
51+ $ this ->rowBuilder = new TableRowBuilder ($ this ->formatter , $ config );
52+ $ this ->headerBuilder = new TableHeaderBuilder ($ config );
53+
5254 if ($ config ->groupByClass ) {
53- $ this ->renderGroupedByClass ($ metricsCollection , $ config );
55+ $ this ->renderGroupedByClass ($ metricsCollection , $ config, $ output );
5456 return ;
5557 }
5658
57- $ this ->renderAllMethodsInSingleTable ($ metricsCollection , $ config );
59+ $ this ->renderAllMethodsInSingleTable ($ metricsCollection , $ config, $ output );
5860 }
5961
6062 /**
6163 * @param CognitiveMetricsCollection $metricsCollection
6264 * @param CognitiveConfig $config
65+ * @param OutputInterface $output
6366 * @throws CognitiveAnalysisException
6467 */
65- private function renderGroupedByClass (CognitiveMetricsCollection $ metricsCollection , CognitiveConfig $ config ): void
68+ private function renderGroupedByClass (CognitiveMetricsCollection $ metricsCollection , CognitiveConfig $ config, OutputInterface $ output ): void
6669 {
6770 $ groupedByClass = $ metricsCollection ->groupBy ('class ' );
6871
@@ -74,7 +77,7 @@ private function renderGroupedByClass(CognitiveMetricsCollection $metricsCollect
7477 $ rows = $ this ->buildRowsForClass ($ metrics , $ config );
7578 if (count ($ rows ) > 0 ) {
7679 $ filename = $ this ->getFilenameFromMetrics ($ metrics );
77- $ this ->renderTable ((string )$ className , $ rows , $ filename );
80+ $ this ->renderTable ((string )$ className , $ rows , $ filename, $ output );
7881 }
7982 }
8083 }
@@ -110,15 +113,16 @@ private function getFilenameFromMetrics(CognitiveMetricsCollection $metrics): st
110113 /**
111114 * @param CognitiveMetricsCollection $metricsCollection
112115 * @param CognitiveConfig $config
116+ * @param OutputInterface $output
113117 * @throws CognitiveAnalysisException
114118 */
115- private function renderAllMethodsInSingleTable (CognitiveMetricsCollection $ metricsCollection , CognitiveConfig $ config ): void
119+ private function renderAllMethodsInSingleTable (CognitiveMetricsCollection $ metricsCollection , CognitiveConfig $ config, OutputInterface $ output ): void
116120 {
117121 $ rows = $ this ->buildRowsForSingleTable ($ metricsCollection , $ config );
118122 $ totalMethods = count ($ rows );
119123
120124 if ($ totalMethods > 0 ) {
121- $ this ->renderSingleTable ($ rows , $ totalMethods );
125+ $ this ->renderSingleTable ($ rows , $ totalMethods, $ output );
122126 }
123127 }
124128
@@ -143,38 +147,40 @@ private function buildRowsForSingleTable(CognitiveMetricsCollection $metricsColl
143147 * @param string $className
144148 * @param array<int, mixed> $rows
145149 * @param string $filename
150+ * @param OutputInterface $output
146151 */
147- private function renderTable (string $ className , array $ rows , string $ filename ): void
152+ private function renderTable (string $ className , array $ rows , string $ filename, OutputInterface $ output ): void
148153 {
149- $ table = new Table ($ this -> output );
154+ $ table = new Table ($ output );
150155 $ table ->setStyle ('box ' );
151156 $ table ->setHeaders ($ this ->getTableHeaders ());
152157
153- $ this -> output ->writeln ("<info>Class: $ className</info> " );
154- $ this -> output ->writeln ("<info>File: $ filename</info> " );
158+ $ output ->writeln ("<info>Class: $ className</info> " );
159+ $ output ->writeln ("<info>File: $ filename</info> " );
155160
156161 $ table ->setRows ($ rows );
157162 $ table ->render ();
158163
159- $ this -> output ->writeln ("" );
164+ $ output ->writeln ("" );
160165 }
161166
162167 /**
163168 * @param array<int, mixed> $rows
164169 * @param int $totalMethods
170+ * @param OutputInterface $output
165171 */
166- private function renderSingleTable (array $ rows , int $ totalMethods ): void
172+ private function renderSingleTable (array $ rows , int $ totalMethods, OutputInterface $ output ): void
167173 {
168- $ table = new Table ($ this -> output );
174+ $ table = new Table ($ output );
169175 $ table ->setStyle ('box ' );
170176 $ table ->setHeaders ($ this ->getSingleTableHeaders ());
171177
172- $ this -> output ->writeln ("<info>All Methods ( $ totalMethods total)</info> " );
178+ $ output ->writeln ("<info>All Methods ( $ totalMethods total)</info> " );
173179
174180 $ table ->setRows ($ rows );
175181 $ table ->render ();
176182
177- $ this -> output ->writeln ("" );
183+ $ output ->writeln ("" );
178184 }
179185
180186 /**
0 commit comments