承接 staabm/phpstan-baseline-analysis 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

staabm/phpstan-baseline-analysis

Composer 安装命令:

composer require --dev staabm/phpstan-baseline-analysis

包简介

README 文档

README

Analyzes PHPStan baseline files and creates aggregated error trend-reports.

Read more in the Blog post.

You need at least one of the supported PHPStan RuleSets/Rules configured in your project, to get meaningful results.

Installation

composer require staabm/phpstan-baseline-analysis --dev

Supported Rules

PHPStan RuleSets

PHPStan Rules

  • PHPStan\Rules\PhpDoc\InvalidPhpDocTagValueRule

Symplify PHPStan Rules

  • Symplify\PHPStanRules\Rules\Explicit\NoMixedMethodCallerRule
  • Symplify\PHPStanRules\Rules\Explicit\NoMixedPropertyFetcherRule

tomasvotruba/cognitive-complexity Rules

  • TomasVotruba\CognitiveComplexity\Rules\ClassLikeCognitiveComplexityRule

tomasvotruba/type-coverage Rules

  • TomasVotruba\TypeCoverage\Rules\ParamTypeCoverageRule
  • TomasVotruba\TypeCoverage\Rules\PropertyTypeCoverageRule
  • TomasVotruba\TypeCoverage\Rules\ReturnTypeCoverageRule

tomasvotruba/unused-public Rules

  • TomasVotruba\UnusedPublic\Rules\UnusedPublicClassConstRule
  • TomasVotruba\UnusedPublic\Rules\UnusedPublicClassMethodRule
  • TomasVotruba\UnusedPublic\Rules\UnusedPublicPropertyRule

example report

Starting from the current directory, the command will recursively search for files matching the glob pattern and report a summary for each baseline found.

$ phpstan-baseline-analyze *phpstan-baseline.neon
Analyzing app/portal/phpstan-baseline.neon
  Overall-Errors: 41
  Classes-Cognitive-Complexity: 70
  Deprecations: 2
  Invalid-Phpdocs: 5
  Unknown-Types: 1
  Anonymous-Variables: 4
  Native-Property-Type-Coverage: 1
  Native-Param-Type-Coverage: 27
  Native-Return-Type-Coverage: 4
  Unused-Symbols: 3

example error filtering

Filter a existing baseline and output only errors NOT matching the given filter key:

Tip

This can be helpful to remove a class of errors out of an existing baseline, so PHPStan will start reporting them again.

$ phpstan-baseline-filter *phpstan-baseline.neon --exclude=Unknown-Types

Filter a existing baseline and output only errors matching the given filter key:

$ phpstan-baseline-filter *phpstan-baseline.neon --include=Invalid-Phpdocs

Currently supported filter keys can be found in the source.

example graph analysis

$ git clone ...

$ phpstan-baseline-analyze *phpstan-baseline.neon --json > now.json

$ git checkout `git rev-list -n 1 --before="1 week ago" HEAD`
$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > 1-week-ago.json

$ git checkout `git rev-list -n 1 --before="2 week ago" HEAD`
$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > 2-weeks-ago.json

$ php phpstan-baseline-graph '*.json' > result.html

PHPStan baseline analysis graph

example trend analysis

the following example shows the evolution of errors in your phpstan baselines. see the trend between 2 different points in time like:

$ git clone ...

$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > now.json

$ git checkout `git rev-list -n 1 --before="1 week ago" HEAD`

$ phpstan-baseline-analyze '*phpstan-baseline.neon' --json > reference.json

$ phpstan-baseline-trend reference.json now.json
Analyzing Trend for app/portal/phpstan-baseline.neon
  Overall-Errors: 30 -> 17 => improved
  Classes-Cognitive-Complexity: 309 -> 177 => improved
  Deprecations: 1 -> 2 => worse
  Invalid-Phpdocs: 3 -> 1 => good
  Unknown-Types: 5 -> 15 => worse
  Anonymous-Variables: 4 -> 3 => good
  Unused-Symbols: 1 -> 1 => good
  Native-Return-Type-Coverage: 20 -> 2 => worse
  Native-Property-Type-Coverage: 3 -> 3 => good
  Native-Param-Type-Coverage: 4 -> 40 => improved

Usage example in a scheduled GitHub Action with Mattermost notification

Copy the following workflow into your repository. Make sure to adjust as needed:

  • adjust the cron schedule pattern
  • actions/checkout might require a token - e.g. for private repos
  • adjust the comparison period, as you see fit
  • adjust the notification to your needs - e.g. use Slack, Discord, E-Mail,..
name: Trends Analyse

on:
  workflow_dispatch:
  schedule:
    - cron: '0 8 * * 4'

jobs:

  behat:
    name: Trends
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - run: "composer global require staabm/phpstan-baseline-analysis"
      - run: echo "$(composer global config bin-dir --absolute --quiet)" >> $GITHUB_PATH

      - uses: actions/checkout@v2
        with:
          fetch-depth: 50 # fetch the last X commits.

      - run: "phpstan-baseline-analyze '*phpstan-baseline.neon' --json > ../now.json"

      - run: git checkout `git rev-list -n 1 --before="1 week ago" HEAD`

      - run: "phpstan-baseline-analyze '*phpstan-baseline.neon' --json > ../reference.json"

      - name: analyze trend
        shell: php {0}
        run: |
          <?php
          exec('phpstan-baseline-trend ../reference.json ../now.json > ../trend.txt', $output, $exitCode);
          $project = '${{ github.repository }}';

          if ($exitCode == 0) {
            # improvements
            file_put_contents(
              'mattermost.json',
              json_encode(["username" => "github-action-trend-bot", "text" => $project ." :tada:\n". file_get_contents("../trend.txt")])
            );
          }
          elseif ($exitCode == 1) {
            # steady
            file_put_contents(
              'mattermost.json',
              json_encode(["username" => "github-action-trend-bot", "text" => $project ." :green_heart:\n". file_get_contents("../trend.txt")])
            );
          }
          elseif ($exitCode == 2) {
            # got worse
            file_put_contents(
              'mattermost.json',
              json_encode(["username" => "github-action-trend-bot", "text" => $project ." :broken_heart:\n". file_get_contents("../trend.txt")])
            );
          }

      - run: 'curl -X POST -H "Content-Type: application/json" -d @mattermost.json ${{ secrets.MATTERMOST_WEBHOOK_URL }}'
        if: always()

💌 Give back some love

Consider supporting the project, so we can make this tool even better even faster for everyone.

staabm/phpstan-baseline-analysis 适用场景与选型建议

staabm/phpstan-baseline-analysis 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 110.08k 次下载、GitHub Stars 达 84, 最近一次更新时间为 2021 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「static analysis」 「dev」 「PHPStan」 「phpstan-extension」 「baseline analysis」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 staabm/phpstan-baseline-analysis 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 staabm/phpstan-baseline-analysis 我们能提供哪些服务?
定制开发 / 二次开发

基于 staabm/phpstan-baseline-analysis 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 110.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 84
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 84
  • Watchers: 3
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-04