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
6 changes: 2 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest ]
php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
php-version: [ '8.1', '8.2', '8.3', '8.4', '8.5' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
-
Expand All @@ -47,9 +47,7 @@ jobs:
php-version: ${{ matrix.php-version }}
-
name: Update dependencies
run: |
composer remove --dev shipmonk/coverage-guard --no-update
composer update --no-progress --${{ matrix.dependency-version }} --prefer-dist --no-interaction
run: composer update --no-progress --${{ matrix.dependency-version }} --prefer-dist --no-interaction
-
name: Run tests
run: composer check:tests
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"static analysis"
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"phpstan/phpstan": "^2.1.33"
},
"require-dev": {
Expand Down
279 changes: 147 additions & 132 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@

<exclude-pattern>tests/*/data/*</exclude-pattern>

<config name="php_version" value="70400"/>
<config name="php_version" value="80100"/>
<config name="installed_paths" value="vendor/slevomat/coding-standard,vendor/shipmonk/coding-standard"/>

<rule ref="ShipMonkCodingStandard">
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden"/><!-- It removes @dataProvider, but PHPUnit 9 does not yet have #[DataProvider] -->
</rule>

<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration">
<properties>
<property name="onlySingleLine" value="false"/>
</properties>
</rule>
</ruleset>
14 changes: 1 addition & 13 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ includes:

parameters:
phpVersion:
min: 70400
min: 80100
max: 80599
internalErrorsCountLimit: 1
paths:
Expand Down Expand Up @@ -45,20 +45,8 @@ parameters:
PHPStan\Rules\Rule: Rule
PhpParser\NodeVisitor: Visitor
ShipMonk\PHPStan\RuleTestCase: RuleTest
enforceClosureParamNativeTypehint:
enabled: false # we support even PHP 7.4, some typehints cannot be used

ignoreErrors:
-
message: "#Class BackedEnum not found\\.#"
path: src/Rule/BackedEnumGenericsRule.php
reportUnmatched: false # fails only for PHP < 8 https://github.com/phpstan/phpstan/issues/6290

-
message: "#Call to method PHPStan\\\\Reflection\\\\ClassReflection::isEnum\\(\\) will always evaluate to false\\.#"
path: src/Rule/ForbidProtectedEnumMethodRule.php
reportUnmatched: false # fails only for PHP < 8 https://github.com/phpstan/phpstan-src/pull/3925/files#diff-df58b1c8117cfa9b77453fb2cc8fdeeb0803ad0acfd2dec85a441a8fa5a53c06R24

-
message: "#but it's missing from the PHPDoc @throws tag\\.$#" # allow uncatched exceptions in tests
path: tests/*
Expand Down
8 changes: 4 additions & 4 deletions src/Rule/AllowComparingOnlyComparableTypesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if (
Expand Down Expand Up @@ -109,7 +109,7 @@ private function isComparable(Type $type): bool

private function isComparableTogether(
Type $leftType,
Type $rightType
Type $rightType,
): bool
{
$intType = new IntegerType();
Expand Down Expand Up @@ -150,7 +150,7 @@ private function isComparableTogether(
}

for ($i = 0; $i < count($leftValueTypes); $i++) {
if (!$this->isComparableTogether($leftValueTypes[$i], $rightValueTypes[$i])) { // @phpstan-ignore offsetAccess.notFound
if (!$this->isComparableTogether($leftValueTypes[$i], $rightValueTypes[$i])) { // @phpstan-ignore offsetAccess.notFound, offsetAccess.notFound
return false;
}
}
Expand All @@ -168,7 +168,7 @@ private function isComparableTogether(
*/
private function containsOnlyTypes(
Type $checkedType,
array $allowedTypes
array $allowedTypes,
): bool
{
$allowedType = TypeCombinator::union(...$allowedTypes);
Expand Down
4 changes: 2 additions & 2 deletions src/Rule/BackedEnumGenericsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
$classReflection = $node->getClassReflection();
Expand Down Expand Up @@ -60,7 +60,7 @@ public function processNode(

private function hasGenericsTag(
ClassReflection $classReflection,
string $expectedTag
string $expectedTag,
): bool
{
if ($classReflection->isBackedEnum()) {
Expand Down
20 changes: 5 additions & 15 deletions src/Rule/ClassSuffixNamingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,24 @@
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function strlen;
use function substr_compare;
use function str_ends_with;

/**
* @implements Rule<InClassNode>
*/
class ClassSuffixNamingRule implements Rule
{

private ReflectionProvider $reflectionProvider;

/**
* @var array<class-string, string>
*/
private array $superclassToSuffixMapping;

private bool $validated = false;

/**
* @param array<class-string, string> $superclassToSuffixMapping
*/
public function __construct(
ReflectionProvider $reflectionProvider,
array $superclassToSuffixMapping = []
private readonly ReflectionProvider $reflectionProvider,
private readonly array $superclassToSuffixMapping = [],
)
{
$this->reflectionProvider = $reflectionProvider;
$this->superclassToSuffixMapping = $superclassToSuffixMapping;
}

private function validateSuperclassToSuffixMapping(): void
Expand Down Expand Up @@ -65,7 +55,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
$this->validateSuperclassToSuffixMapping();
Expand All @@ -92,7 +82,7 @@ public function processNode(

$className = $classReflection->getName();

if (substr_compare($className, $suffix, -strlen($suffix)) !== 0) {
if (!str_ends_with($className, $suffix)) {
$error = RuleErrorBuilder::message("Class name $className should end with $suffix suffix")
->identifier('shipmonk.invalidClassSuffix')
->build();
Expand Down
12 changes: 3 additions & 9 deletions src/Rule/EnforceClosureParamNativeTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@
class EnforceClosureParamNativeTypehintRule implements Rule
{

private PhpVersion $phpVersion;

private bool $allowMissingTypeWhenInferred;

public function __construct(
PhpVersion $phpVersion,
bool $allowMissingTypeWhenInferred
private readonly PhpVersion $phpVersion,
private readonly bool $allowMissingTypeWhenInferred,
)
{
$this->phpVersion = $phpVersion;
$this->allowMissingTypeWhenInferred = $allowMissingTypeWhenInferred;
}

public function getNodeType(): string
Expand All @@ -43,7 +37,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if (!$node instanceof InClosureNode && !$node instanceof InArrowFunctionNode) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceEnumMatchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if (!$node instanceof Identical && !$node instanceof NotIdentical) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceIteratorToArrayPreserveKeysRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if (!$node->name instanceof Name) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceListReturnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
$methodReflection = $scope->getFunction();
Expand Down
25 changes: 8 additions & 17 deletions src/Rule/EnforceNativeReturnTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,12 @@
class EnforceNativeReturnTypehintRule implements Rule
{

private FileTypeMapper $fileTypeMapper;

private PhpVersion $phpVersion;

private bool $treatPhpDocTypesAsCertain;

public function __construct(
FileTypeMapper $fileTypeMapper,
PhpVersion $phpVersion,
bool $treatPhpDocTypesAsCertain
private readonly FileTypeMapper $fileTypeMapper,
private readonly PhpVersion $phpVersion,
private readonly bool $treatPhpDocTypesAsCertain,
)
{
$this->fileTypeMapper = $fileTypeMapper;
$this->phpVersion = $phpVersion;
$this->treatPhpDocTypesAsCertain = $treatPhpDocTypesAsCertain;
}

public function getNodeType(): string
Expand All @@ -70,7 +61,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if ($this->treatPhpDocTypesAsCertain === false) {
Expand Down Expand Up @@ -114,7 +105,7 @@ private function getTypehintByType(
Scope $scope,
bool $typeFromPhpDoc,
bool $alwaysThrowsException,
bool $topLevel
bool $topLevel,
): ?string
{
if ($type instanceof MixedType || $this->isUnionTypeWithMixed($type)) {
Expand Down Expand Up @@ -212,7 +203,7 @@ private function getTypeOfReturnStatements(ReturnStatementsNode $node): Type

private function getPhpDocReturnType(
Node $node,
Scope $scope
Scope $scope,
): ?Type
{
$docComment = $node->getDocComment();
Expand Down Expand Up @@ -251,7 +242,7 @@ private function getUnionTypehint(
Type $type,
Scope $scope,
bool $typeFromPhpDoc,
bool $alwaysThrowsException
bool $alwaysThrowsException,
): ?string
{
if (!$type instanceof UnionType) {
Expand Down Expand Up @@ -295,7 +286,7 @@ private function getIntersectionTypehint(
Type $type,
Scope $scope,
bool $typeFromPhpDoc,
bool $alwaysThrowsException
bool $alwaysThrowsException,
): ?string
{
if (!$type instanceof IntersectionType) { // @phpstan-ignore phpstanApi.instanceofType
Expand Down
12 changes: 3 additions & 9 deletions src/Rule/EnforceReadonlyPublicPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@
class EnforceReadonlyPublicPropertyRule implements Rule
{

private bool $excludePropertyWithDefaultValue;

private PhpVersion $phpVersion;

public function __construct(
bool $excludePropertyWithDefaultValue,
PhpVersion $phpVersion
private readonly bool $excludePropertyWithDefaultValue,
private readonly PhpVersion $phpVersion,
)
{
$this->excludePropertyWithDefaultValue = $excludePropertyWithDefaultValue;
$this->phpVersion = $phpVersion;
}

public function getNodeType(): string
Expand All @@ -40,7 +34,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if (!$this->phpVersion->supportsReadOnlyProperties()) {
Expand Down
13 changes: 5 additions & 8 deletions src/Rule/ForbidArithmeticOperationOnNonNumberRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
class ForbidArithmeticOperationOnNonNumberRule implements Rule
{

private bool $allowNumericString;

public function __construct(bool $allowNumericString)
public function __construct(private readonly bool $allowNumericString)
{
$this->allowNumericString = $allowNumericString;
}

public function getNodeType(): string
Expand All @@ -48,7 +45,7 @@ public function getNodeType(): string
*/
public function processNode(
Node $node,
Scope $scope
Scope $scope,
): array
{
if (
Expand Down Expand Up @@ -78,7 +75,7 @@ public function processNode(
private function processUnary(
Expr $expr,
Scope $scope,
string $operator
string $operator,
): array
{
$exprType = $scope->getType($expr);
Expand All @@ -105,7 +102,7 @@ private function processBinary(
Expr $left,
Expr $right,
Scope $scope,
string $operator
string $operator,
): array
{
$leftType = $scope->getType($left);
Expand Down Expand Up @@ -154,7 +151,7 @@ private function buildBinaryErrors(
string $operator,
string $type,
Type $leftType,
Type $rightType
Type $rightType,
): array
{
$errorMessage = sprintf(
Expand Down
Loading
Loading