Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/Rules/DeadCode/PossiblyPureStaticCallCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
return null;
}

if (
$expr->class->toLowerString() === 'static'
&& $scope->isInClass()
&& !$scope->getClassReflection()->isFinal()
&& !$methodReflection->isFinal()->yes()

Check warning on line 70 in src/Rules/DeadCode/PossiblyPureStaticCallCollector.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $expr->class->toLowerString() === 'static' && $scope->isInClass() && !$scope->getClassReflection()->isFinal() - && !$methodReflection->isFinal()->yes() + && $methodReflection->isFinal()->no() && !$methodReflection->isPrivate() ) { return null;

Check warning on line 70 in src/Rules/DeadCode/PossiblyPureStaticCallCollector.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $expr->class->toLowerString() === 'static' && $scope->isInClass() && !$scope->getClassReflection()->isFinal() - && !$methodReflection->isFinal()->yes() + && $methodReflection->isFinal()->no() && !$methodReflection->isPrivate() ) { return null;
&& !$methodReflection->isPrivate()
) {
return null;
}

return [$methodReflection->getDeclaringClass()->getName(), $methodReflection->getName(), $node->getStartLine()];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public function testRule(): void
'Call to CallToStaticMethodWithoutImpurePoints\SubSubY::mySubSubFunc() on a separate line has no effect.',
21,
],
[
'Call to CallToStaticMethodWithoutImpurePoints\y::myFunc() on a separate line has no effect.',
48,
],
[
'Call to CallToStaticMethodWithoutImpurePoints\y::myFunc() on a separate line has no effect.',
53,
Expand All @@ -59,6 +55,11 @@ public function testRule(): void
]);
}

public function testBug12062(): void
{
$this->analyse([__DIR__ . '/data/bug-12062.php'], []);
}

#[RequiresPhp('>= 8.5')]
public function testPipeOperator(): void
{
Expand Down
38 changes: 38 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-12062.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);

namespace Bug12062;

abstract class Base
{
public static function get(mixed $param): mixed
{
static::validateParam($param);
return $param;
}

public static function set(mixed $param, mixed $value): void
{
static::validateParam($param);
}

public static function clear(mixed $param): void
{
static::validateParam($param);
}

protected static function validateParam(mixed $param): bool
{
return true;
}
}

abstract class IntParam extends Base
{
protected static function validateParam(mixed $param): bool
{
if (!is_int($param)) {
throw new \InvalidArgumentException('Must be int');
}
return true;
}
}
Loading