Skip to content

Commit

Permalink
chore: add bind for CyclomaticComplexity.
Browse files Browse the repository at this point in the history
  • Loading branch information
ytetsuro committed Aug 14, 2022
1 parent c71035c commit e85493d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComplexityCountableNode>
) {}

Expand Down
1 change: 0 additions & 1 deletion src/Sabik/Analyzer/LanguageAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
27 changes: 20 additions & 7 deletions src/Sabik/DIContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -62,6 +66,7 @@ container.bind<Analyzer>(Analyzer).toSelf();
container.bind<ASTNodeExtractor>(ASTNodeExtractor).toSelf().inSingletonScope();
container.bind<MetricsAnalyzer>(MetricsAnalyzer).toSelf();
container.bind<CalculatorForAST>(Types.codeMetricsCalculatorForAST).to(CognitiveComplexityCalculator);
container.bind<CalculatorForAST>(Types.codeMetricsCalculatorForAST).to(CyclomaticComplexityCalculator);
container.bind<CalculatorForAST>(Types.codeMetricsCalculatorForAST).to(HalsteadCalculator);
container.bind<CalculatorForAST>(Types.codeMetricsCalculatorForAST).to(LineOfCodeCalculator);
container.bind<CalculatorForMetrics>(Types.codeMetricsCalculatorForMetrics).to(MaintainabilityCalculator);
Expand All @@ -73,8 +78,12 @@ container
.to(LineOfCodeConverterForPHP)
.whenAnyAncestorNamed('PHP');
container
.bind<Converter<ComplexityCountableNode>>(Types.cognitiveComplexityConverter)
.to(ComplexityConverterForPHP)
.bind<Converter<CognitiveComplexityCountableNode>>(Types.cognitiveComplexityConverter)
.to(CognitiveComplexityConverterForPHP)
.whenAnyAncestorNamed('PHP');
container
.bind<Converter<CyclomaticComplexityCountableNode>>(Types.cyclomaticComplexityConverter)
.to(CyclomaticComplexityConverterForPHP)
.whenAnyAncestorNamed('PHP');
container
.bind<Converter<HalsteadCountableNode>>(Types.halsteadConverter)
Expand All @@ -86,8 +95,12 @@ container
.to(LineOfCodeConverterForTypeScript)
.whenAnyAncestorNamed('TypeScript');
container
.bind<Converter<ComplexityCountableNode>>(Types.cognitiveComplexityConverter)
.to(ComplexityConverterForTypeScript)
.bind<Converter<CognitiveComplexityCountableNode>>(Types.cognitiveComplexityConverter)
.to(CognitiveComplexityConverterForTypeScript)
.whenAnyAncestorNamed('TypeScript');
container
.bind<Converter<CyclomaticComplexityCountableNode>>(Types.cyclomaticComplexityConverter)
.to(CyclomaticComplexityConverterForTypeScript)
.whenAnyAncestorNamed('TypeScript');
container
.bind<Converter<HalsteadCountableNode>>(Types.halsteadConverter)
Expand Down
1 change: 1 addition & 0 deletions src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit e85493d

Please sign in to comment.