88use Phauthentic \CognitiveCodeAnalysis \Business \Cognitive \CognitiveMetricsCollection ;
99use Phauthentic \CognitiveCodeAnalysis \CognitiveAnalysisException ;
1010use Phauthentic \CognitiveCodeAnalysis \Config \CognitiveConfig ;
11+ use Phauthentic \CognitiveCodeAnalysis \Config \ConfigService ;
1112use Symfony \Component \Console \Helper \Table ;
1213use Symfony \Component \Console \Output \OutputInterface ;
1314
1718class CognitiveMetricTextRenderer
1819{
1920 public function __construct (
20- private readonly OutputInterface $ output
21+ private readonly OutputInterface $ output ,
22+ private readonly ConfigService $ configService ,
2123 ) {
2224 }
2325
@@ -30,12 +32,12 @@ private function metricExceedsThreshold(CognitiveMetrics $metric, CognitiveConfi
3032
3133 /**
3234 * @param CognitiveMetricsCollection $metricsCollection
33- * @param CognitiveConfig $config
3435 * @throws CognitiveAnalysisException
3536 */
36- public function render (CognitiveMetricsCollection $ metricsCollection, CognitiveConfig $ config ): void
37+ public function render (CognitiveMetricsCollection $ metricsCollection ): void
3738 {
3839 $ groupedByClass = $ metricsCollection ->groupBy ('class ' );
40+ $ config = $ this ->configService ->getConfig ();
3941
4042 foreach ($ groupedByClass as $ className => $ metrics ) {
4143 if (count ($ metrics ) === 0 ) {
@@ -162,7 +164,7 @@ private function metricsToArray(CognitiveMetrics $metrics): array
162164 'ifCount ' => $ metrics ->getIfCount (),
163165 'ifNestingLevel ' => $ metrics ->getIfNestingLevel (),
164166 'elseCount ' => $ metrics ->getElseCount (),
165- 'score ' => $ metrics ->getScore () > 0.5
167+ 'score ' => $ metrics ->getScore () > $ this -> configService -> getConfig ()-> scoreThreshold
166168 ? '<error> ' . $ metrics ->getScore () . '</error> '
167169 : '<info> ' . $ metrics ->getScore () . '</info> ' ,
168170 ];
0 commit comments