Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4

11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto

/cache export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
50 changes: 50 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Checks
on:
pull_request:
push:
branches:
- master
jobs:
checks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
-
name: Checkout code
uses: actions/checkout@v4
-
name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
-
name: Install dependencies
run: composer install --no-progress --prefer-dist --no-interaction

-
name: Run checks
run: composer check

tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: [ '8.1', '8.2', '8.3', '8.4' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
-
name: Checkout code
uses: actions/checkout@v4
-
name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
-
name: Update dependencies
run: composer update --no-progress --${{ matrix.dependency-version }} --no-interaction
-
name: Run tests
run: composer check:tests
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor
/cache/*
!/cache/.gitkeep
/.idea
/phpstan.neon
/composer.lock
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# PHPStan error ignore inliner

Allows you to easily **inline ignore your PHPStan errors** via `@phpstan-ignore` comment.

So instead of:

```neon
parameters:
ignoreErrors:
-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
path: ../src/App/User.php
count: 1
```

You will have the ignored error directly in the source code `src/App/User.php`:

```php
class User {

public function updateSurname(string $surname): void
{
if (empty($surname)) { // @phpstan-ignore empty.notAllowed
throw new EmptyNameException();
}
}

}
```

## Installation:

```sh
composer require --dev shipmonk/phpstan-ignore-inliner
```

## Usage

```sh
vendor/bin/phpstan --error-format=json | vendor/bin/inline-phpstan-ignores
```

## Contributing
- Check your code by `composer check`
- Autofix coding-style by `composer fix:cs`
- All functionality must be tested
36 changes: 36 additions & 0 deletions bin/inline-phpstan-ignores
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

namespace ShipMonk\PHPStan\Errors;

use JsonException;

$autoloadFiles = [
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
];

foreach ($autoloadFiles as $autoloadFile) {
if (file_exists($autoloadFile)) {
require_once $autoloadFile;
break;
}
}

$usage = "\n\nUsage:\n$ vendor/bin/phpstan --error-format=json | vendor/bin/inline-phpstan-ignores\n";

try {
$io = new Io();
$input = $io->readInput();
$errorsData = json_decode($input, associative: true, flags: JSON_THROW_ON_ERROR);
$errors = $errorsData['files'] ?? throw new FailureException('No \'files\' key found on input JSON.');

$inliner = new InlineIgnoreInliner($io);
$inliner->inlineErrors($errors);

$errorsCount = count($errors);
echo "Done, $errorsCount errors processed.\n";

} catch (JsonException | FailureException $e) {
echo $e->getMessage() . $usage;
}
Empty file added cache/.gitkeep
Empty file.
68 changes: 68 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "shipmonk/phpstan-ignore-inliner",
"description": "Inline your PHPStan error ignores into the source files via @phpstan-ignore comments.",
"license": [
"MIT"
],
"type": "phpstan-extension",
"keywords": [
"dev",
"phpstan",
"phpstan errors",
"phpstan extension",
"error identifier"
],
"require": {
"php": "^8.1",
"phpstan/phpstan": "^2"
},
"require-dev": {
"editorconfig-checker/editorconfig-checker": "^10.7.0",
"ergebnis/composer-normalize": "2.47.0",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan-phpunit": "^2.0.6",
"phpstan/phpstan-strict-rules": "^2.0.4",
"phpunit/phpunit": "^10.5.46",
"shipmonk/phpstan-rules": "^4.1.2",
"slevomat/coding-standard": "^8.18.0"
},
"autoload": {
"psr-4": {
"ShipMonk\\PHPStan\\Errors\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ShipMonk\\PHPStan\\Errors\\": "tests/"
}
},
"bin": [
"bin/inline-phpstan-ignores"
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
"scripts": {
"check": [
"@check:composer",
"@check:ec",
"@check:cs",
"@check:types",
"@check:tests"
],
"check:composer": [
"composer normalize --dry-run --no-check-lock --no-update-lock",
"composer validate --strict"
],
"check:cs": "phpcs",
"check:ec": "ec src tests",
"check:tests": "phpunit tests",
"check:types": "phpstan analyse -vv --ansi",
"fix:cs": "phpcbf"
}
}
Loading