Skip to content

Commit f245acb

Browse files
authored
Merge pull request #31 from nextras/updates
Updates for PHPStan 2.0
2 parents 0bc4d46 + 79c9996 commit f245acb

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
php-version: [ '8.1', '8.2', '8.3' ]
20+
php-version: [ '8.1', '8.2', '8.3', '8.4' ]
2121
deps: [ 'lowest', 'newest' ]
2222
exclude:
23-
- php-version: '8.1'
24-
deps: lowest
2523
- php-version: '8.2'
2624
deps: lowest
25+
- php-version: '8.3'
26+
deps: lowest
27+
- php-version: '8.4'
28+
deps: lowest
2729

2830
runs-on: ubuntu-latest
2931

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)