Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
/tests/fixtures/drupal/sites/simpletest/
.phpunit.result.cache
.idea/

# Temporary files
phpstan.phar
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function getTypeFromMethodCall(
}
if ($varType->isCount()) {
return $varType->hasAccessCheck()
? new IntegerType()
? IntegerRangeType::createAllGreaterThanOrEqualTo(0)
: new EntityQueryExecuteWithoutAccessCheckCountType();
}
if ($varType instanceof ConfigEntityQueryType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
namespace mglaman\PHPStanDrupal\Type\EntityQuery;

use PHPStan\Type\IntegerType;
use PHPStan\Type\VerbosityLevel;

final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerType
{

public function describe(VerbosityLevel $level = null): string

Check failure on line 13 in src/Type/EntityQuery/EntityQueryExecuteWithoutAccessCheckCountType.php

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.4

Deprecated in PHP 8.4: Parameter #1 $level (PHPStan\Type\VerbosityLevel) is implicitly nullable via default value null.
{
return 'int<0, max>';
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should extend IntegerRangeType instead of IntegerType

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can this class extend IntegerRangeType and not override describe, instead just ensure the minimum is always 0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the class to extend IntegerRangeType and removed the custom describe() method. The constructor now initializes with parent::__construct(0, null) to ensure the minimum is always 0, creating a non-negative integer range. Commit 9e073fc.

14 changes: 7 additions & 7 deletions tests/src/Type/data/entity-query-execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
->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')
->accessCheck(TRUE)
->execute()
);
assertType(
'int',
'int<0, max>',
\Drupal::entityQuery('node')
->accessCheck(TRUE)
->count()
Expand All @@ -48,7 +48,7 @@
assertType('array<int, string>', $query->execute());
$query = \Drupal::entityTypeManager()->getStorage('node')->getQuery()
->accessCheck(TRUE)->count();
assertType('int', $query->execute());
assertType('int<0, max>', $query->execute());

assertType(
'array<string, string>',
Expand All @@ -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()
Expand All @@ -87,4 +87,4 @@
assertType('array<string, string>', $query->execute());
$query = \Drupal::entityTypeManager()->getStorage('block')->getQuery()
->accessCheck(TRUE)->count();
assertType('int', $query->execute());
assertType('int<0, max>', $query->execute());
Loading