Skip to content

Commit

Permalink
Upgrade code to PHPStan 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jdecool committed Nov 11, 2024
1 parent d08ad92 commit 1934f09
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"require": {
"php": "^7.4|^8.0",
"myclabs/php-enum": "^1.2",
"phpstan/phpstan": "^1.0"
"phpstan/phpstan": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0|^9.0"
Expand Down
4 changes: 2 additions & 2 deletions src/Rule/EnumAlwaysUsedConstantsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Timeweb\PHPStan\Rule;

use MyCLabs\Enum\Enum;
use PHPStan\Reflection\ConstantReflection;
use PHPStan\Reflection\ClassConstantReflection;
use PHPStan\Rules\Constants\AlwaysUsedClassConstantsExtension;

class EnumAlwaysUsedConstantsExtension implements AlwaysUsedClassConstantsExtension
{
public function isAlwaysUsed(ConstantReflection $constant): bool
public function isAlwaysUsed(ClassConstantReflection $constant): bool
{
return $constant->getDeclaringClass()->isSubclassOf(Enum::class);
}
Expand Down
15 changes: 10 additions & 5 deletions src/Rule/NoDuplicateEnumValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Node\ClassConstantsNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;

/**
Expand Down Expand Up @@ -43,11 +44,15 @@ public function processNode(Node $node, Scope $scope): array
}

return [
sprintf(
'Enum %s contains duplicated values for %s properties',
$classReflection->getName(),
implode(', ', $duplicatedKeysValue)
),
RuleErrorBuilder::message(
sprintf('Enum %s contains duplicated values for %s properties',
$classReflection->getName(),
implode(', ', $duplicatedKeysValue)
)
)
->line($node->getLine())
->identifier('timewebEnum.duplicatedValues')
->build(),
];
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Reflection/EnumMethodsClassReflectionExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ public function testEnumMethodProperties(string $propertyName): void
{
$classReflection = $this->reflectionProvider->getClass(EnumFixture::class);
$methodReflection = $this->reflectionExtension->getMethod($classReflection, $propertyName);
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());

$this->assertSame($propertyName, $methodReflection->getName());
$this->assertSame($classReflection, $methodReflection->getDeclaringClass());
$this->assertTrue($methodReflection->isStatic());
$this->assertFalse($methodReflection->isPrivate());
$this->assertTrue($methodReflection->isPublic());
$this->assertSame(EnumFixture::class, $parametersAcceptor->getReturnType()->describe(VerbosityLevel::value()));
}

/**
Expand Down

0 comments on commit 1934f09

Please sign in to comment.