From 13aa3c7ca45ec641de4c449acd6c6b3003609617 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 16 Aug 2025 22:44:12 +0000 Subject: [PATCH 1/4] Initial plan From 2c8d1724ee07a757cc40c7474b8d9ed928f0dc31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 16 Aug 2025 22:56:41 +0000 Subject: [PATCH 2/4] Implement non-negative integer return type for entity query count operations Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com> --- .../EntityQueryDynamicReturnTypeExtension.php | 3 ++- ...tityQueryExecuteWithoutAccessCheckCountType.php | 9 ++++++--- tests/src/Type/data/entity-query-execute.php | 14 +++++++------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php b/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php index c543e86c..e2cebad9 100644 --- a/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php +++ b/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php @@ -9,6 +9,7 @@ use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\ArrayType; use PHPStan\Type\DynamicMethodReturnTypeExtension; +use PHPStan\Type\IntegerRangeType; use PHPStan\Type\IntegerType; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; @@ -63,7 +64,7 @@ public function getTypeFromMethodCall( } if ($varType->isCount()) { return $varType->hasAccessCheck() - ? new IntegerType() + ? IntegerRangeType::createAllGreaterThanOrEqualTo(0) : new EntityQueryExecuteWithoutAccessCheckCountType(); } if ($varType instanceof ConfigEntityQueryType) { diff --git a/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php b/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php index 8c42c5ea..e4fe8cd6 100644 --- a/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php +++ b/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php @@ -4,9 +4,12 @@ namespace mglaman\PHPStanDrupal\Type\EntityQuery; -use PHPStan\Type\IntegerType; +use PHPStan\Type\IntegerRangeType; -final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerType +final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerRangeType { - + public function __construct() + { + parent::__construct(0, null); + } } diff --git a/tests/src/Type/data/entity-query-execute.php b/tests/src/Type/data/entity-query-execute.php index ce9a89f0..b828d28d 100644 --- a/tests/src/Type/data/entity-query-execute.php +++ b/tests/src/Type/data/entity-query-execute.php @@ -15,14 +15,14 @@ ->execute() ); assertType( - 'int', + 'int<0, max>', \Drupal::entityTypeManager()->getStorage('node')->getQuery() ->accessCheck(TRUE) ->count() ->execute() ); assertType( - 'int', + 'int<0, max>', \Drupal::entityTypeManager()->getStorage('node')->getQuery() ->count() ->condition('foo', 'bar') @@ -30,7 +30,7 @@ ->execute() ); assertType( - 'int', + 'int<0, max>', \Drupal::entityQuery('node') ->accessCheck(TRUE) ->count() @@ -48,7 +48,7 @@ assertType('array', $query->execute()); $query = \Drupal::entityTypeManager()->getStorage('node')->getQuery() ->accessCheck(TRUE)->count(); -assertType('int', $query->execute()); +assertType('int<0, max>', $query->execute()); assertType( 'array', @@ -62,14 +62,14 @@ ->execute() ); assertType( - 'int', + 'int<0, max>', \Drupal::entityTypeManager()->getStorage('block')->getQuery() ->accessCheck(TRUE) ->count() ->execute() ); assertType( - 'int', + 'int<0, max>', \Drupal::entityQuery('block') ->accessCheck(TRUE) ->count() @@ -87,4 +87,4 @@ assertType('array', $query->execute()); $query = \Drupal::entityTypeManager()->getStorage('block')->getQuery() ->accessCheck(TRUE)->count(); -assertType('int', $query->execute()); +assertType('int<0, max>', $query->execute()); From acdc4e5c692825f8a36b0087902aab2d208510a2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 Aug 2025 12:44:35 +0000 Subject: [PATCH 3/4] Fix private constructor issue and ensure non-negative int return type Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com> --- .gitignore | 3 +++ .../EntityQueryExecuteWithoutAccessCheckCountType.php | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1a5079cb..ae062345 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ /tests/fixtures/drupal/sites/simpletest/ .phpunit.result.cache .idea/ + +# Temporary files +phpstan.phar diff --git a/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php b/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php index e4fe8cd6..a08e59fc 100644 --- a/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php +++ b/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php @@ -4,12 +4,14 @@ namespace mglaman\PHPStanDrupal\Type\EntityQuery; -use PHPStan\Type\IntegerRangeType; +use PHPStan\Type\IntegerType; +use PHPStan\Type\VerbosityLevel; -final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerRangeType +final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerType { - public function __construct() + + public function describe(VerbosityLevel $level = null): string { - parent::__construct(0, null); + return 'int<0, max>'; } } From 9e073fcb47eb6b7ddb3040bfbb23be5b05b46034 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 Aug 2025 17:22:57 +0000 Subject: [PATCH 4/4] Change EntityQueryExecuteWithoutAccessCheckCountType to extend IntegerRangeType with minimum 0 Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com> --- .../EntityQueryExecuteWithoutAccessCheckCountType.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php b/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php index a08e59fc..312934a8 100644 --- a/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php +++ b/src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php @@ -4,14 +4,14 @@ namespace mglaman\PHPStanDrupal\Type\EntityQuery; -use PHPStan\Type\IntegerType; -use PHPStan\Type\VerbosityLevel; +use PHPStan\Type\IntegerRangeType; -final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerType +final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerRangeType { - public function describe(VerbosityLevel $level = null): string + public function __construct() { - return 'int<0, max>'; + // Initialize as a non-negative integer range (0 to max) + parent::__construct(0, null); } }