dzunke / panaly

项目分析工具 - 将不同来源的质量工具汇集到单一结果源

dev-main 2024-08-13 17:59 UTC

This package is auto-updated.

Last update: 2024-09-13 18:16:05 UTC


README

Build Status License

该项目旨在提供一个可扩展的工具,用于分析项目的源代码以获得各种指标。无论您是否有代码覆盖率报告、静态分析器的基线,还是文件系统指标,Panaly 都可以根据您的自定义配置将它们聚合在一起,并提供全面的报告。

插件系统确保了从配置到指标收集、存储和报告的每一步都可以进行自定义。未来的更新将启用主动事件监听,允许插件进一步自定义分析过程。

功能

  • 可扩展的插件系统
  • 可定制的指标收集
  • 全面报告

设置

⚠️ 正在进行中的项目

使用 Composer 安装此包

composer require --dev panaly/panaly

创建一个 panaly.dist.yaml 文件,并根据您需要的插件进行配置。如果没有任何插件,则不会执行任何操作。请参阅此存储库中的示例配置以获取指导。

用法

默认情况下,CLI 命令会搜索 panaly.dist.yaml 配置文件。您可以使用 -c 选项指定不同的配置文件。

vendor/bin/panaly -c my-own-config.yaml

精选插件列表

指标插件

存储插件

报告插件

其他插件

示例配置

panaly.dist.yaml
# panaly.dist.yaml
plugins: # Registered plugins that deliver single metrics that could be utilized for metric groups
  Namespace/Of/The/Project/FilesystemPlugin: ~ # registers a "filesystem_directory_count" and a "filesystem_file_count" metric
  Namespace/Of/Another/Project/PHPStanBaselinePlugin: ~ # registers a simple "phpstan_baseline_total_count" metric
  I/Have/A/Storage/Engine/LocalJsonStoragePlugin: ~ # registers a "local_json" storage and also a "metric_history_timeframe" metric that shows from / to string of all-time metric reading
  My/Own/Plugin/HtmlReportPlugin: ~ # registers the "my_own_html_reporting" reporting that takes the result collection of the metrics and does something with it

groups:
  group1:
      title: "My Metrics"
      metrics:
          metric_history_timeframe:
              title: "Metrics in Storage (Timeframe)"
              storage: local_json
  group2:
      title: "Filesystem Metrics"
      metrics:
          filesystem_directory_count: ~
          filesystem_file_count:
              title: "Total project files"
              paths:
                  - src
                  - tests
          i_am_a_custom_identifier:
              metric: filesystem_file_count # This overwrites the key and is the metric to be utilized
              title: "Just test files"
              paths:
                  - src
                  - tests
  group3:
      title: "Static Analysis Metrics"
      metrics:
          phpstan_baseline_total_count:
              title: "PHPStan Debts"
              baseline: .baselines/phpstan-baseline.neon

storage:
  local_json:
      path: var/metric_storage

reporting:
  my_own_html_reporting: ~

插件

Panaly 依赖于广泛的插件系统,并且本身不提供指标收集、存储或报告功能。每个插件都可以专注于单个任务,或者从指标收集到存储处理和报告生成提供完整的功能集。

插件对于配置 Panaly 运行至关重要。每个插件都有一个基类,该类定义了它与 Panaly 的交互方式以及它提供的功能。插件必须实现 Panaly\Plugin\Plugin 接口,该接口定义了一个 initialize 方法。

插件将接收到完整的应用程序配置、与之关联的特定配置以及运行时配置,其中可以添加指标、存储和报告。它还可以访问事件分发器,以注册监听器/订阅者进行自定义。

插件示例

<?php

declare(strict_types=1);

namespace MyNamespace;

use Panaly\Configuration\ConfigurationFile;
use Panaly\Configuration\RuntimeConfiguration;
use Panaly\Plugin\Plugin;

final class BaselinePlugin implements Plugin
{
    public function initialize(
        ConfigurationFile $configurationFile,
        RuntimeConfiguration $runtimeConfiguration,
        array $options,
    ): void {
        $runtimeConfiguration->addMetric(new MyMetric());
        $runtimeConfiguration->addReporting(new MyReport());
        $runtimeConfiguration->addStorage(new MyStorage());
    }
}

事件

事件系统仍在开发中。未来的更新将允许插件注册事件监听器,使它们能够挂钩到除指标、报告或存储之外的事件。

感谢和许可

Panaly - 项目分析器 © 2024+, Denis Zunke。在 MIT 许可证 下发布。

PHPMetrics 启发 - 感谢您的工具!

GitHub @dzunke  ·  Twitter @DZunke