From f9291d24ba0353ee63f9e894c7d4d64dafee01d1 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Fri, 15 Nov 2024 17:03:05 +0100 Subject: [PATCH 1/2] build with PHP 8.4 --- .github/workflows/build.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c887f94..ebef06b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,13 +17,15 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '8.1', '8.2', '8.3' ] + php-version: [ '8.1', '8.2', '8.3', '8.4' ] deps: [ 'lowest', 'newest' ] exclude: - - php-version: '8.1' - deps: lowest - php-version: '8.2' deps: lowest + - php-version: '8.3' + deps: lowest + - php-version: '8.4' + deps: lowest runs-on: ubuntu-latest From 79c999658ffb3855ed04c9ebb5915fa2de721faa Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Fri, 15 Nov 2024 17:03:25 +0100 Subject: [PATCH 2/2] add support for PHPStan 2.0 (added identifiers) --- composer.json | 4 ++-- src/Rules/SetValueMethodRule.php | 23 +++++++++++---------- tests/testbox/Types/RepositoryTypesTest.php | 9 ++++---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index b1517bf..7abb916 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ ], "require": { "php": ">=8.1", - "phpstan/phpstan": "^1.10.12" + "phpstan/phpstan": "^1.10.12 || ^2.0.0" }, "require-dev": { "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0", "nextras/orm": "~5.0@dev", "nette/tester": "^2.3.1" }, diff --git a/src/Rules/SetValueMethodRule.php b/src/Rules/SetValueMethodRule.php index 706967f..2fef216 100644 --- a/src/Rules/SetValueMethodRule.php +++ b/src/Rules/SetValueMethodRule.php @@ -9,6 +9,7 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\VerbosityLevel; @@ -35,8 +36,6 @@ public function getNodeType(): string /** * @param MethodCall $node - * - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -81,22 +80,22 @@ public function processNode(Node $node, Scope $scope): array } if (!$class->hasProperty($fieldName)) { - $errors[] = sprintf( - 'Entity %s has no $%s property.', - $className, - $fieldName - ); + $errors[] = RuleErrorBuilder::message(sprintf('Entity %s has no $%s property.', $className, $fieldName)) + ->identifier("nextrasOrm.propertyNotFound") + ->build(); continue; } $property = $class->getProperty($fieldName, $scope); if (!$property->isWritable() && $methodName !== 'setReadOnlyValue') { - $errors[] = sprintf( + $errors[] = RuleErrorBuilder::message(sprintf( 'Entity %s: property $%s is read-only.', $className, $fieldName - ); + )) + ->identifier("nextrasOrm.propertyReadOnly") + ->build(); continue; } @@ -106,13 +105,15 @@ public function processNode(Node $node, Scope $scope): array } if (!$propertyType->accepts($valueType, true)->yes()) { - $errors[] = sprintf( + $errors[] = RuleErrorBuilder::message(sprintf( 'Entity %s: property $%s (%s) does not accept %s.', $className, $fieldName, $propertyType->describe(VerbosityLevel::typeOnly()), $valueType->describe(VerbosityLevel::typeOnly()) - ); + )) + ->identifier("nextrasOrm.propertyUnresolvableType") + ->build(); } } diff --git a/tests/testbox/Types/RepositoryTypesTest.php b/tests/testbox/Types/RepositoryTypesTest.php index cb47b20..5088d1b 100644 --- a/tests/testbox/Types/RepositoryTypesTest.php +++ b/tests/testbox/Types/RepositoryTypesTest.php @@ -17,7 +17,10 @@ public function testError(AuthorsRepository $repository, BooksRepository $booksR } - public function testOk(AuthorsRepository $repository): void + /** + * @param AuthorsRepository|BooksRepository $repository2 + */ + public function testOk(AuthorsRepository $repository, $repository2): void { $this->takeAuthor($repository->getByIdChecked(1)); $this->takeAuthor($repository->getByChecked(['id' => 1])); @@ -31,9 +34,7 @@ public function testOk(AuthorsRepository $repository): void $a = $repository->getByIdChecked(1); $this->takeAuthor($repository->persist($a)); - /** @var AuthorsRepository|BooksRepository $someRepo */ - $someRepo = $repository; - foreach ($someRepo->findAll() as $entity) { + foreach ($repository2->findAll() as $entity) { if ($entity instanceof Author) { $this->takeAuthor($entity); } else {