Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -4,9 +4,14 @@

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()
{
// Initialize as a non-negative integer range (0 to max)
parent::__construct(0, null);

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

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.2

Calling PHPStan\Type\IntegerRangeType::__construct() is not covered by backward compatibility promise. The method might change in a minor PHPStan version.

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

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.2

Call to private method __construct() of class PHPStan\Type\IntegerRangeType.

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

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.1

Calling PHPStan\Type\IntegerRangeType::__construct() is not covered by backward compatibility promise. The method might change in a minor PHPStan version.

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

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.1

Call to private method __construct() of class PHPStan\Type\IntegerRangeType.

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

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.4

Calling PHPStan\Type\IntegerRangeType::__construct() is not covered by backward compatibility promise. The method might change in a minor PHPStan version.

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

View workflow job for this annotation

GitHub Actions / Linting | PHP 8.4

Call to private method __construct() of class PHPStan\Type\IntegerRangeType.
}
}
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