Skip to content

Commit 46786f8

Browse files
authored
Ignore accessCheck on config entity queries (#517)
1 parent dbd50be commit 46786f8

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Rules/Drupal/EntityQuery/EntityQueryHasAccessCheckRule.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace mglaman\PHPStanDrupal\Rules\Drupal\EntityQuery;
66

7+
use mglaman\PHPStanDrupal\Type\EntityQuery\ConfigEntityQueryType;
78
use mglaman\PHPStanDrupal\Type\EntityQuery\EntityQueryExecuteWithoutAccessCheckCountType;
89
use mglaman\PHPStanDrupal\Type\EntityQuery\EntityQueryExecuteWithoutAccessCheckType;
910
use PhpParser\Node;
@@ -38,6 +39,11 @@ public function processNode(Node $node, Scope $scope): array
3839
return [];
3940
}
4041

42+
$parent = $scope->getType($node->var);
43+
if ($parent instanceof ConfigEntityQueryType) {
44+
return [];
45+
}
46+
4147
return [
4248
RuleErrorBuilder::message(
4349
'Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.'

tests/src/Rules/EntityQueryHasAccessCheckRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,10 @@ public function cases(): \Generator
132132
[__DIR__.'/data/bug-496.php'],
133133
[]
134134
];
135+
136+
yield 'bug-479.php' => [
137+
[__DIR__.'/data/bug-479.php'],
138+
[]
139+
];
135140
}
136141
}

tests/src/Rules/data/bug-479.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug479Example;
4+
5+
class TestClass {
6+
7+
/**
8+
* Tests non-chained entity queries with access check.
9+
*/
10+
public function bug479(string $entity_type): void
11+
{
12+
$query = \Drupal::entityQuery('entity_form_display');
13+
$query->execute();
14+
}
15+
}

0 commit comments

Comments
 (0)