juampi92/phpstan-baseline-warnings 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

juampi92/phpstan-baseline-warnings

最新稳定版本:v0.4

Composer 安装命令:

composer require juampi92/phpstan-baseline-warnings

包简介

PHPStan baseline warnings generator for GitHub Actions

README 文档

README

Latest Version on Packagist Downloads Per Month GitHub Tests Action Status PHP from Packagist

TL;DR: Compare your PR's changed files with your PHPStan baseline, and let developers know they modified a file that has skipped errors, prompting them to fix them!

$ vendor/bin/phpstan-baseline-warnings src/Foo.php src/Bar.php src/Baz.php

::warning file=src/Foo.php,line=0,title=Found 3 errors that occur a total of 6 times:%0A- `#^Property Juampi92\\PhpstanBaselineWarnings\\Domain\\BaselineParser\:\:\$storage is never read, only written\.$#` : 3 times%0A- `#^Unsafe usage of new static\(\)\.$#` : 2 times
::warning file=src/Baz.php,line=0,title=Found 1 errors that occur a total of 2 times:%0A- `#^Unsafe usage of new static\(\)\.$#` : 2 times

It also comes avaialble as a github action!

Example of a PR with warnings

A Composer package that analyzes PHPStan baseline files and generates GitHub PR warning annotations for files with baseline-ignored errors. This helps teams maintain code quality by highlighting technical debt that's been temporarily suppressed through baselines whenever that file is modified.

Installation

You can install the package via composer, or directly using a github action (see below).

composer require --dev juampi92/phpstan-baseline-warnings

Usage

After installing, you can run the command to analyze specific files against your PHPStan baseline:

# Basic usage with default baseline path
vendor/bin/phpstan-baseline-warnings src/MyClass.php src/OtherClass.php

# Specify a custom baseline path and base directory
vendor/bin/phpstan-baseline-warnings \
    --baseline-path=tools/phpstan-baseline.neon \
    --base-dir=../ \
    src/Domain/Entity/Post.php \
    src/Domain/Repository/PostRepository.php

The command will:

  1. Read your PHPStan baseline file (default: phpstan-baseline.neon)
  2. Check if the provided files have any baseline-ignored errors
  3. Generate GitHub-compatible warning annotations for those files

Options

  • --baseline-path: Path to your PHPStan baseline file (default: ./phpstan-baseline.neon)
  • --base-dir: Base directory for resolving relative paths. Useful when your phpstan config is inside a sub-folder (default: ./)

GitHub Action

You can also use this tool as a GitHub Action in your workflows:

name: PHPStan Baseline Warnings
on:
  pull_request:

jobs:
  phpstan-baseline-warnings:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: PHPStan Baseline Warnings
        uses: juampi92/phpstan-baseline-warnings@v0.4
        with:
          baseline-path: ./phpstan-baseline.neon
          base-dir: ./

This will analyze your PHPStan baseline file and create warning annotations in your GitHub repository.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-24