From e85493d90fb04e4a5939ba05563cf93d68075a18 Mon Sep 17 00:00:00 2001 From: Tetsuro Yoshikawa Date: Sun, 31 Jul 2022 00:26:29 +0900 Subject: [PATCH] chore: add bind for CyclomaticComplexity. --- .../CyclomaticComplexity/Calculator.ts | 2 +- src/Sabik/Analyzer/LanguageAnalyzer.ts | 1 - src/Sabik/DIContainer.ts | 27 ++++++++++++++----- src/types/Types.ts | 1 + 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Analyzer/CodeMetricsCalculator/CyclomaticComplexity/Calculator.ts b/src/Analyzer/CodeMetricsCalculator/CyclomaticComplexity/Calculator.ts index 84a8feb..ce3abc5 100644 --- a/src/Analyzer/CodeMetricsCalculator/CyclomaticComplexity/Calculator.ts +++ b/src/Analyzer/CodeMetricsCalculator/CyclomaticComplexity/Calculator.ts @@ -13,7 +13,7 @@ import { Converter } from '../../Adapter/Converter'; export class Calculator implements CalculatorForAST { constructor( @inject(MethodAnalyzer) private readonly analyzer: MethodAnalyzer, - @inject(Types.cognitiveComplexityConverter) + @inject(Types.cyclomaticComplexityConverter) private readonly converter: Converter ) {} diff --git a/src/Sabik/Analyzer/LanguageAnalyzer.ts b/src/Sabik/Analyzer/LanguageAnalyzer.ts index bd426d8..a52d981 100644 --- a/src/Sabik/Analyzer/LanguageAnalyzer.ts +++ b/src/Sabik/Analyzer/LanguageAnalyzer.ts @@ -10,7 +10,6 @@ export abstract class LanguageAnalyzer { analyze(files: File[]) { const analyzableFiles = files.filter((file) => this.extensions.includes(file.extension)); - return this.analyzer.analyze(analyzableFiles); } } diff --git a/src/Sabik/DIContainer.ts b/src/Sabik/DIContainer.ts index afe3297..bccbaf3 100644 --- a/src/Sabik/DIContainer.ts +++ b/src/Sabik/DIContainer.ts @@ -20,6 +20,7 @@ import { Analyzer } from './Analyzer/Analyzer'; import { ASTNodeExtractor } from '../Analyzer/ASTNodeExtractor'; import { Analyzer as MetricsAnalyzer } from '../Analyzer/Analyzer'; import { Calculator as CognitiveComplexityCalculator } from '../Analyzer/CodeMetricsCalculator/CognitiveComplexity/Calculator'; +import { Calculator as CyclomaticComplexityCalculator } from '../Analyzer/CodeMetricsCalculator/CyclomaticComplexity/Calculator'; import { Calculator as HalsteadCalculator } from '../Analyzer/CodeMetricsCalculator/Halstead/Calculator'; import { Calculator as LineOfCodeCalculator } from '../Analyzer/CodeMetricsCalculator/LineOfCode/Calculator'; import { Calculator as MaintainabilityCalculator } from '../Analyzer/CodeMetricsCalculator/Maintainability/Calculator'; @@ -30,13 +31,16 @@ import { Converter } from '../Analyzer/Adapter/Converter'; import { LineOfCodeCountableNode } from '../Analyzer/CodeMetricsCalculator/LineOfCode/Adapter/LineOfCodeCountableNode'; import { LineOfCode as LineOfCodeConverterForPHP } from '../Language/PHP/Converter/LineOfCode'; import { Halstead as HalsteadConverterForPHP } from '../Language/PHP/Converter/Halstead'; -import { CognitiveComplexity as ComplexityConverterForPHP } from '../Language/PHP/Converter/CognitiveComplexity'; +import { CognitiveComplexity as CognitiveComplexityConverterForPHP } from '../Language/PHP/Converter/CognitiveComplexity'; +import { CyclomaticComplexity as CyclomaticComplexityConverterForPHP } from '../Language/PHP/Converter/CyclomaticComplexity'; import { ASTGenerator as ASTGeneratorForPHP } from '../Language/PHP/ASTGenerator'; -import { ComplexityCountableNode } from '../Analyzer/CodeMetricsCalculator/CognitiveComplexity/Adapter/ComplexityCountableNode'; +import { ComplexityCountableNode as CognitiveComplexityCountableNode } from '../Analyzer/CodeMetricsCalculator/CognitiveComplexity/Adapter/ComplexityCountableNode'; +import { ComplexityCountableNode as CyclomaticComplexityCountableNode } from '../Analyzer/CodeMetricsCalculator/CyclomaticComplexity/Adapter/ComplexityCountableNode'; import { HalsteadCountableNode } from '../Analyzer/CodeMetricsCalculator/Halstead/Adapter/HalsteadCountableNode'; import { LineOfCode as LineOfCodeConverterForTypeScript } from '../Language/TypeScript/Converter/LineOfCode'; import { Halstead as HalsteadConverterForTypeScript } from '../Language/TypeScript/Converter/Halstead'; -import { Complexity as ComplexityConverterForTypeScript } from '../Language/TypeScript/Converter/CognitiveComplexity'; +import { Complexity as CognitiveComplexityConverterForTypeScript } from '../Language/TypeScript/Converter/CognitiveComplexity'; +import { Complexity as CyclomaticComplexityConverterForTypeScript } from '../Language/TypeScript/Converter/CyclomaticComplexity'; import { ASTGenerator as ASTGeneratorForTypeScript } from '../Language/TypeScript/ASTGenerator'; import { CalculatorForAST } from '../Analyzer/FromASTNode/CalculatorForAST'; import { CalculatorForMetrics } from '../Analyzer/FromOtherMetrics/CalculatorForMetrics'; @@ -62,6 +66,7 @@ container.bind(Analyzer).toSelf(); container.bind(ASTNodeExtractor).toSelf().inSingletonScope(); container.bind(MetricsAnalyzer).toSelf(); container.bind(Types.codeMetricsCalculatorForAST).to(CognitiveComplexityCalculator); +container.bind(Types.codeMetricsCalculatorForAST).to(CyclomaticComplexityCalculator); container.bind(Types.codeMetricsCalculatorForAST).to(HalsteadCalculator); container.bind(Types.codeMetricsCalculatorForAST).to(LineOfCodeCalculator); container.bind(Types.codeMetricsCalculatorForMetrics).to(MaintainabilityCalculator); @@ -73,8 +78,12 @@ container .to(LineOfCodeConverterForPHP) .whenAnyAncestorNamed('PHP'); container - .bind>(Types.cognitiveComplexityConverter) - .to(ComplexityConverterForPHP) + .bind>(Types.cognitiveComplexityConverter) + .to(CognitiveComplexityConverterForPHP) + .whenAnyAncestorNamed('PHP'); +container + .bind>(Types.cyclomaticComplexityConverter) + .to(CyclomaticComplexityConverterForPHP) .whenAnyAncestorNamed('PHP'); container .bind>(Types.halsteadConverter) @@ -86,8 +95,12 @@ container .to(LineOfCodeConverterForTypeScript) .whenAnyAncestorNamed('TypeScript'); container - .bind>(Types.cognitiveComplexityConverter) - .to(ComplexityConverterForTypeScript) + .bind>(Types.cognitiveComplexityConverter) + .to(CognitiveComplexityConverterForTypeScript) + .whenAnyAncestorNamed('TypeScript'); +container + .bind>(Types.cyclomaticComplexityConverter) + .to(CyclomaticComplexityConverterForTypeScript) .whenAnyAncestorNamed('TypeScript'); container .bind>(Types.halsteadConverter) diff --git a/src/types/Types.ts b/src/types/Types.ts index 175a2f0..993317f 100644 --- a/src/types/Types.ts +++ b/src/types/Types.ts @@ -11,6 +11,7 @@ export const Types = { analyzer: Symbol.for('Analyzer'), lineOfCodeConverter: Symbol.for('LineOfCodeConverter'), cognitiveComplexityConverter: Symbol.for('CognitiveComplexityConverter'), + cyclomaticComplexityConverter: Symbol.for('CyclomaticComplexityConverter'), halsteadConverter: Symbol.for('HalsteadConverter'), codeMetricsCalculatorForAST: Symbol.for('CodeMetricsCalculatorForAST'), codeMetricsCalculatorForMetrics: Symbol.for('CodeMetricsCalculatorForMetrics'),