Skip to content

Commit 3702711

Browse files
committed
kick off
1 parent 3f5697e commit 3702711

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
/vendor

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "rector/rector-compat-tests",
3+
"description": "Tests for compatibility with PHPStand and PHPUnit preload magic",
4+
"require-dev": {
5+
"php": "^8.2",
6+
"phpunit/phpunit": "^9.6|^10.*|^11.*|^12.*",
7+
"rector/rector": "^2.2",
8+
"phpstan/phpstan": "^2.1"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"Rector\\RectorCompatTests\\": "src"
13+
}
14+
},
15+
"autoload-dev": {
16+
"psr-4": {
17+
"Rector\\RectorCompatTests\\Tests\\": "tests"
18+
}
19+
}
20+
}

src/PHPStan/CustomPHPStanRule.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\RectorCompatTests\PHPStan;
6+
7+
use PhpParser\Node;
8+
use PhpParser\Node\Stmt\Class_;
9+
use PHPStan\Analyser\Scope;
10+
use PHPStan\Rules\Rule;
11+
use PHPStan\Rules\RuleError;
12+
use PHPStan\Rules\RuleErrorBuilder;
13+
14+
/**
15+
* @implements Rule<Class_>
16+
*/
17+
final class CustomPHPStanRule implements Rule
18+
{
19+
public function getNodeType(): string
20+
{
21+
return Class_::class;
22+
}
23+
24+
/**
25+
* @param Class_ $node
26+
* @return RuleError[]
27+
*/
28+
public function processNode(Node $node, Scope $scope): array
29+
{
30+
if ($node->isFinal()) {
31+
return [];
32+
}
33+
34+
$ruleErrorMessage = RuleErrorBuilder::message(
35+
sprintf('Class "%s" is not final.', $node->name->toString())
36+
)->build();
37+
38+
return [$ruleErrorMessage];
39+
}
40+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\RectorCompatTests\Tests\PHPStan\CustomPHPStanRule;
4+
5+
use PHPStan\Rules\Rule;
6+
use PHPStan\Testing\RuleTestCase;
7+
use Rector\RectorCompatTests\PHPStan\CustomPHPStanRule;
8+
9+
final class CustomPHPStanRuleTest extends RuleTestCase
10+
{
11+
// @todo
12+
13+
protected function getRule(): Rule
14+
{
15+
return new CustomPHPStanRule();
16+
}
17+
}

0 commit comments

Comments
 (0)