admin管理员组

文章数量:1561811

开源项目 cognitive-complexity 使用教程

cognitive-complexityPHPStan rules to measure cognitive complexity of your classes and methods项目地址:https://gitcode/gh_mirrors/co/cognitive-complexity

1. 项目的目录结构及介绍

cognitive-complexity/
├── bin/
│   └── analyze.php
├── config/
│   ├── config.yaml
│   └── services.yaml
├── src/
│   ├── Analyzer/
│   │   └── CognitiveComplexityAnalyzer.php
│   ├── Command/
│   │   └── AnalyzeCommand.php
│   └── Utils/
│       └── FileReader.php
├── tests/
│   └── Analyzer/
│       └── CognitiveComplexityAnalyzerTest.php
├── vendor/
├── .gitignore
├── composer.json
└── README.md
  • bin/: 包含项目的可执行文件。
  • config/: 包含项目的配置文件。
  • src/: 包含项目的源代码。
    • Analyzer/: 包含分析器类。
    • Command/: 包含命令行命令类。
    • Utils/: 包含工具类。
  • tests/: 包含测试文件。
  • vendor/: 包含Composer依赖包。
  • .gitignore: Git忽略文件配置。
  • composer.json: Composer配置文件。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

bin/analyze.php 是项目的启动文件,负责初始化环境和执行分析命令。

#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\Console\Application;
use TomasVotruba\CognitiveComplexity\Command\AnalyzeCommand;

$application = new Application();
$application->add(new AnalyzeCommand());
$application->run();

3. 项目的配置文件介绍

config/config.yaml

parameters:
    source_directory: 'src'
    output_file: 'cognitive_complexity_report.txt'
  • source_directory: 指定源代码目录。
  • output_file: 指定输出报告文件。

config/services.yaml

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    TomasVotruba\CognitiveComplexity\Analyzer\CognitiveComplexityAnalyzer: ~
    TomasVotruba\CognitiveComplexity\Command\AnalyzeCommand: ~
    TomasVotruba\CognitiveComplexity\Utils\FileReader: ~
  • services: 定义服务容器中的服务。
    • CognitiveComplexityAnalyzer: 分析器服务。
    • AnalyzeCommand: 命令行命令服务。
    • FileReader: 文件读取工具服务。

cognitive-complexityPHPStan rules to measure cognitive complexity of your classes and methods项目地址:https://gitcode/gh_mirrors/co/cognitive-complexity

本文标签: 开源项目教程CognitiveComplexity