Skip to content

Commit 79c9996

Browse files
committed
add support for PHPStan 2.0 (added identifiers)
1 parent f9291d2 commit 79c9996

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
],
1212
"require": {
1313
"php": ">=8.1",
14-
"phpstan/phpstan": "^1.10.12"
14+
"phpstan/phpstan": "^1.10.12 || ^2.0.0"
1515
},
1616
"require-dev": {
1717
"phpstan/extension-installer": "^1.1",
18-
"phpstan/phpstan-deprecation-rules": "^1.0",
18+
"phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0",
1919
"nextras/orm": "~5.0@dev",
2020
"nette/tester": "^2.3.1"
2121
},

src/Rules/SetValueMethodRule.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Reflection\ClassReflection;
1010
use PHPStan\Reflection\ReflectionProvider;
1111
use PHPStan\Rules\Rule;
12+
use PHPStan\Rules\RuleErrorBuilder;
1213
use PHPStan\Type\VerbosityLevel;
1314

1415

@@ -35,8 +36,6 @@ public function getNodeType(): string
3536

3637
/**
3738
* @param MethodCall $node
38-
*
39-
* @return string[]
4039
*/
4140
public function processNode(Node $node, Scope $scope): array
4241
{
@@ -81,22 +80,22 @@ public function processNode(Node $node, Scope $scope): array
8180
}
8281

8382
if (!$class->hasProperty($fieldName)) {
84-
$errors[] = sprintf(
85-
'Entity %s has no $%s property.',
86-
$className,
87-
$fieldName
88-
);
83+
$errors[] = RuleErrorBuilder::message(sprintf('Entity %s has no $%s property.', $className, $fieldName))
84+
->identifier("nextrasOrm.propertyNotFound")
85+
->build();
8986
continue;
9087
}
9188

9289
$property = $class->getProperty($fieldName, $scope);
9390

9491
if (!$property->isWritable() && $methodName !== 'setReadOnlyValue') {
95-
$errors[] = sprintf(
92+
$errors[] = RuleErrorBuilder::message(sprintf(
9693
'Entity %s: property $%s is read-only.',
9794
$className,
9895
$fieldName
99-
);
96+
))
97+
->identifier("nextrasOrm.propertyReadOnly")
98+
->build();
10099
continue;
101100
}
102101

@@ -106,13 +105,15 @@ public function processNode(Node $node, Scope $scope): array
106105
}
107106

108107
if (!$propertyType->accepts($valueType, true)->yes()) {
109-
$errors[] = sprintf(
108+
$errors[] = RuleErrorBuilder::message(sprintf(
110109
'Entity %s: property $%s (%s) does not accept %s.',
111110
$className,
112111
$fieldName,
113112
$propertyType->describe(VerbosityLevel::typeOnly()),
114113
$valueType->describe(VerbosityLevel::typeOnly())
115-
);
114+
))
115+
->identifier("nextrasOrm.propertyUnresolvableType")
116+
->build();
116117
}
117118
}
118119

tests/testbox/Types/RepositoryTypesTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public function testError(AuthorsRepository $repository, BooksRepository $booksR
1717
}
1818

1919

20-
public function testOk(AuthorsRepository $repository): void
20+
/**
21+
* @param AuthorsRepository|BooksRepository $repository2
22+
*/
23+
public function testOk(AuthorsRepository $repository, $repository2): void
2124
{
2225
$this->takeAuthor($repository->getByIdChecked(1));
2326
$this->takeAuthor($repository->getByChecked(['id' => 1]));
@@ -31,9 +34,7 @@ public function testOk(AuthorsRepository $repository): void
3134
$a = $repository->getByIdChecked(1);
3235
$this->takeAuthor($repository->persist($a));
3336

34-
/** @var AuthorsRepository|BooksRepository $someRepo */
35-
$someRepo = $repository;
36-
foreach ($someRepo->findAll() as $entity) {
37+
foreach ($repository2->findAll() as $entity) {
3738
if ($entity instanceof Author) {
3839
$this->takeAuthor($entity);
3940
} else {

0 commit comments

Comments
 (0)