Skip to content

Commit ca5c60f

Browse files
committed
Merge branch 'main' into 496
2 parents be817ad + 10819c6 commit ca5c60f

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Extension for [PHPStan](https://phpstan.org/) to allow analysis of Drupal code.
66

77
## Sponsors
88

9-
<a href="https://www.undpaul.de/"><img src="https://www.undpaul.de/themes/custom/undpaul3/logo.svg" alt="undpaul" width="250" /></a> <a href="https://www.iodigital.com/en"><img src="https://www.drupal.org/files/iO-logo%2Bblack.png" alt="iO" width="225" /></a>
9+
<a href="https://www.undpaul.de/"><img src="https://www.undpaul.de/themes/custom/undpaul3/logo.svg" alt="undpaul" width="250" /></a>
1010

1111
[Would you like to sponsor?](https://github.com/sponsors/mglaman)
1212

src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function processNode(Node $node, Scope $scope): array
2929
}
3030
$scopeClassReflection = $scope->getClassReflection();
3131

32+
// Enums cannot have dependency injection.
33+
if ($scopeClassReflection->isEnum()) {
34+
return [];
35+
}
36+
3237
$allowed_list = [
3338
// Ignore tests.
3439
'PHPUnit\Framework\Test',

tests/src/Rules/GlobalDrupalDependencyInjectionRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public function resultData(): \Generator
5252
__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/src/Entity/ReflectionEntityTest.php',
5353
[],
5454
];
55+
56+
if (PHP_VERSION_ID >= 80100) {
57+
yield [
58+
__DIR__ . '/data/bug-500.php',
59+
[],
60+
];
61+
}
62+
5563
}
5664

5765

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bug500;
4+
5+
enum MyEnum {
6+
case ONE;
7+
case TWO;
8+
public function getTitle(): string {
9+
return match($this) {
10+
self::ONE => (string) \Drupal::translation()->translate('One'),
11+
self::TWO => (string) \Drupal::translation()->translate('Two'),
12+
};
13+
}
14+
}

0 commit comments

Comments
 (0)