Skip to content

Commit

Permalink
Enhancement: Add rule error identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Nov 30, 2024
1 parent b7a42f7 commit 6e3f667
Show file tree
Hide file tree
Showing 54 changed files with 376 additions and 45 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: "Collect code coverage with Xdebug and phpunit/phpunit"
env:
XDEBUG_MODE: "coverage"
run: "vendor/bin/phpunit --colors=always --configuration=test/Integration/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml"

- name: "Send code coverage report to codecov.io"
uses: "codecov/[email protected]"
Expand Down Expand Up @@ -358,5 +358,8 @@ jobs:
with:
dependencies: "${{ matrix.dependencies }}"

- name: "Run unit tests with phpunit/phpunit"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --testsuite=unit"

- name: "Run integration tests with phpunit/phpunit"
run: "vendor/bin/phpunit --colors=always --configuration=test/Integration/phpunit.xml"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --testsuite=integration"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.4.0...main`][2.4.0...main].

### Added

- Added rule error identifiers ([#875]), by [@localheinz]

## [`2.4.0`][2.4.0]

For a full diff see [`2.3.0...2.4.0`][2.3.0...2.4.0].
Expand Down Expand Up @@ -523,6 +527,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
[#735]: https://github.com/ergebnis/phpstan-rules/pull/735
[#862]: https://github.com/ergebnis/phpstan-rules/pull/862
[#872]: https://github.com/ergebnis/phpstan-rules/pull/872
[#875]: https://github.com/ergebnis/phpstan-rules/pull/875

[@enumag]: https://github.com/enumag
[@ergebnis]: https://github.com/ergebnis
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
it: coding-standards security-analysis static-code-analysis tests ## Runs the coding-standards, security-analysis, static-code-analysis, and tests targets

.PHONY: code-coverage
code-coverage: vendor ## Collects coverage from running integration tests with phpunit/phpunit
vendor/bin/phpunit --configuration=test/Integration/phpunit.xml --coverage-text
code-coverage: vendor ## Collects coverage from running unit and integration tests with phpunit/phpunit
vendor/bin/phpunit --configuration=test/phpunit.xml --coverage-text

.PHONY: coding-standards
coding-standards: vendor ## Lints YAML files with yamllint, normalizes composer.json with ergebnis/composer-normalize, and fixes code style issues with friendsofphp/php-cs-fixer
Expand Down Expand Up @@ -39,8 +39,9 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
vendor/bin/phpstan --allow-empty-baseline --configuration=phpstan.neon --generate-baseline=phpstan-baseline.neon --memory-limit=-1

.PHONY: tests
tests: vendor ## Runs integration tests with phpunit/phpunit
vendor/bin/phpunit --configuration=test/Integration/phpunit.xml
tests: vendor ## Runs unit and integration tests with phpunit/phpunit
vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=unit
vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=integration

vendor: composer.json composer.lock
composer validate --strict
Expand Down
3 changes: 2 additions & 1 deletion src/Classes/FinalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Classes;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Comment;
use PhpParser\Node;
use PHPStan\Analyser;
Expand Down Expand Up @@ -107,7 +108,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::final()->toString())->build(),
];
}

Expand Down
5 changes: 3 additions & 2 deletions src/Classes/NoExtendsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Classes;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noExtends()->toString())->build(),
];
}

Expand All @@ -94,7 +95,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noExtends()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Reflection;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::testCaseWithSuffix()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Closures/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Closures;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Closure has a nullable return type declaration.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(),
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Closures/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Closures;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build();
}, $params);
}
}
3 changes: 2 additions & 1 deletion src/Closures/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Closures;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString())->build();
}, $params);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Expressions/NoCompactRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Expressions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Function compact() should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noCompact()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Expressions/NoErrorSuppressionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Expressions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand All @@ -34,7 +35,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Error suppression via "@" should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noErrorSuppression()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Expressions/NoEvalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Expressions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand All @@ -34,7 +35,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct eval() should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noEval()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Expressions/NoIssetRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Expressions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand All @@ -34,7 +35,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct isset() should not be used.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noIsset()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Files/DeclareStrictTypesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Files;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Node\FileNode;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function processNode(
$ruleErrorBuilder = Rules\RuleErrorBuilder::message('File is missing a "declare(strict_types=1)" declaration.');

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::declareStrictTypes()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Functions/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Functions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(),
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Functions/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Functions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -71,7 +72,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build();
}, $params);
}
}
3 changes: 2 additions & 1 deletion src/Functions/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Functions;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString())->build();
}, $params);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Methods/FinalInAbstractClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Methods;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Reflection;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::finalInAbstractClass()->toString())->build(),
];
}
}
3 changes: 2 additions & 1 deletion src/Methods/NoConstructorParameterWithDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Methods;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Reflection;
Expand Down Expand Up @@ -73,7 +74,7 @@ public function processNode(
$parameterName,
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noConstructorParameterWithDefaultValue()->toString())->build();
}, $params);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Methods/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Methods;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Reflection;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(),
];
}

Expand All @@ -66,7 +67,7 @@ public function processNode(
));

return [
$ruleErrorBuilder->build(),
$ruleErrorBuilder->identifier(RuleErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(),
];
}

Expand Down
5 changes: 3 additions & 2 deletions src/Methods/NoParameterWithContainerTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ergebnis\PHPStan\Rules\Methods;

use Ergebnis\PHPStan\Rules\RuleErrorIdentifier;
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Reflection;
Expand Down Expand Up @@ -167,7 +168,7 @@ private static function createError(
$classUsedInTypeDeclaration->getName(),
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build();
}

$ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf(
Expand All @@ -178,6 +179,6 @@ private static function createError(
$classUsedInTypeDeclaration->getName(),
));

return $ruleErrorBuilder->build();
return $ruleErrorBuilder->identifier(RuleErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build();
}
}
Loading

0 comments on commit 6e3f667

Please sign in to comment.