Skip to content

Commit

Permalink
feat: Add support for phpstan 2.0, drop support for older versions.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: phpstan 1.x is not longer supported
  • Loading branch information
Stephan Wentz committed Nov 11, 2024
1 parent 01eb253 commit 5ca2c37
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
],
"minimum-stability": "stable",
"require": {
"php": "^8.1",
"php": "^8.3",
"nette/utils": "^4.0",
"nikic/php-parser": "^4.3|^5.0",
"phpstan/phpstan": "^1.0"
"phpstan/phpstan": "^2.0"
},
"require-dev": {
"brainbits/phpcs-standard": "^7.0",
"php-coveralls/php-coveralls": "^2.0",
"phpstan/phpstan-php-parser": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^10.5"
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^11.0"
},
"scripts": {
"check-all": [
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<!-- arg value="sp"/ -->

<!-- Use brainbits coding standard -->
<rule ref="BrainbitsCodingStandardTest">
<rule ref="Brainbits">
</rule>
</ruleset>
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ includes:
- phar://phpstan.phar/conf/config.levelmax.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-php-parser/extension.neon
- rules.neon

parameters:
Expand Down
10 changes: 5 additions & 5 deletions src/CoversClassExistsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -28,7 +28,7 @@ final class CoversClassExistsRule implements Rule
/** @var bool[] */
private array $alreadyParsedDocComments = [];

public function __construct(private Broker $broker)
public function __construct(private ReflectionProvider $reflectionProvider)
{
}

Expand Down Expand Up @@ -74,7 +74,7 @@ public function processNodeAttribute(Class_ $node, Scope $scope): array
assert($arg->value->class instanceof Name);

$className = (string) $arg->value->class;
if ($this->broker->hasClass($className)) {
if ($this->reflectionProvider->hasClass($className)) {
continue;
}

Expand All @@ -85,7 +85,7 @@ public function processNodeAttribute(Class_ $node, Scope $scope): array

if ($arg->value instanceof String_) {
$className = (string) $arg->value->value;
if ($this->broker->hasClass($className)) {
if ($this->reflectionProvider->hasClass($className)) {
continue;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public function processNodeAnnotation(Class_ $node, Scope $scope): array
}
}

if ($this->broker->hasClass($matches['className'])) {
if ($this->reflectionProvider->hasClass($matches['className'])) {
continue;
}

Expand Down
9 changes: 4 additions & 5 deletions tests/CoversClassExistsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
use BrainbitsPhpStan\CoversClassExistsRule;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* @covers \BrainbitsPhpStan\CoversClassExistsRule
* @extends RuleTestCase<CoversClassExistsRule>
*/
/** @extends RuleTestCase<CoversClassExistsRule> */
#[CoversClass(CoversClassExistsRule::class)]
final class CoversClassExistsRuleTest extends RuleTestCase
{
public function testAttributeRule(): void
Expand All @@ -31,7 +30,7 @@ public function testAnnotationRule(): void

protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = self::createReflectionProvider();

return new CoversClassExistsRule($broker);
}
Expand Down
7 changes: 3 additions & 4 deletions tests/CoversClassPresentRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
use BrainbitsPhpStan\CoversClassPresentRule;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* @covers \BrainbitsPhpStan\CoversClassPresentRule
* @extends RuleTestCase<CoversClassPresentRule>
*/
/** @extends RuleTestCase<CoversClassPresentRule> */
#[CoversClass(CoversClassPresentRule::class)]
final class CoversClassPresentRuleTest extends RuleTestCase
{
public function testAnnotationWithoutUnitRule(): void
Expand Down

0 comments on commit 5ca2c37

Please sign in to comment.