Skip to content

Commit c3db004

Browse files
committed
Adjust logic when returning entity count type with access
1 parent 0bae5bb commit c3db004

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/Type/EntityQuery/EntityQueryCountType.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace mglaman\PHPStanDrupal\Type\EntityQuery;
44

5-
use PHPStan\Type\ObjectType;
6-
75
/**
86
* Type used to represent an entity query instance as count query.
97
*/

src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,21 @@ public function getTypeFromMethodCall(
3939
$varType = $scope->getType($methodCall->var);
4040
$methodName = $methodReflection->getName();
4141

42-
if ($methodName === 'count') {
43-
if ($varType instanceof EntityQueryType) {
44-
$returnType = new EntityQueryCountType(
45-
$varType->getClassName(),
46-
$varType->getSubtractedType(),
47-
$varType->getClassReflection()
48-
);
49-
50-
if ($varType->hasAccessCheck()) {
51-
return $returnType->withAccessCheck();
52-
}
42+
if (!$varType instanceof ObjectType) {
43+
return $defaultReturnType;
44+
}
5345

54-
return $returnType;
46+
if ($methodName === 'count') {
47+
$returnType = new EntityQueryCountType(
48+
$varType->getClassName(),
49+
$varType->getSubtractedType(),
50+
$varType->getClassReflection()
51+
);
52+
if ($varType instanceof EntityQueryType && $varType->hasAccessCheck()) {
53+
return $returnType->withAccessCheck();
5554
}
5655

57-
if ($varType instanceof ObjectType) {
58-
return new EntityQueryCountType(
59-
$varType->getClassName(),
60-
$varType->getSubtractedType(),
61-
$varType->getClassReflection()
62-
);
63-
}
64-
return $defaultReturnType;
56+
return $returnType;
6557
}
6658

6759
if ($methodName === 'execute') {

0 commit comments

Comments
 (0)