Skip to content

Commit ff4f58b

Browse files
authored
Merge pull request #410 from mglaman/fix-1.7.0-compat
Fix PHPStan 1.7.0 incompatibilities
2 parents c7fcb79 + 9d7ca51 commit ff4f58b

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

.github/workflows/phpstan-dev.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: PHPStan dev
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
schedule:
8+
- cron: 0 0 * * *
9+
jobs:
10+
verify:
11+
runs-on: "ubuntu-latest"
12+
name: Lint
13+
steps:
14+
- name: "Checkout"
15+
uses: "actions/checkout@v2"
16+
- name: "Install PHP"
17+
uses: "shivammathur/setup-php@v2"
18+
with:
19+
coverage: "none"
20+
php-version: 8.1
21+
tools: composer:v2
22+
extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, gd
23+
- name: "Bump PHPStan"
24+
run: "composer require --no-update phpstan/phpstan:1.7.x-dev"
25+
- name: "Add phpspec/prophecy-phpunit"
26+
run: "composer require phpspec/prophecy-phpunit:^2 --dev --no-update"
27+
- name: "Install dependencies"
28+
run: "composer update --no-progress --prefer-dist"
29+
- name: "PHPCS"
30+
run: "php vendor/bin/phpcs"
31+
- name: "PHPStan"
32+
run: "php vendor/bin/phpstan analyze"
33+
- name: "PHPUnit"
34+
run: "php vendor/bin/phpunit"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": "^7.4 || ^8.0",
1414
"symfony/finder": "~3.4.5 ||^4.2 || ^5.0 || ^6.0",
15-
"phpstan/phpstan": "^1.0",
15+
"phpstan/phpstan": "^1.7.0",
1616
"symfony/yaml": "~3.4.5 || ^4.2|| ^5.0 || ^6.0",
1717
"webflo/drupal-finder": "^1.2"
1818
},

src/Reflection/EntityFieldsViaMagicReflectionExtension.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
2828
return false;
2929
}
3030

31-
$reflection = $classReflection->getNativeReflection();
3231
// We need to find a way to parse the entity annotation so that at the minimum the `entity_keys` are
3332
// supported. The real fix is Drupal developers _really_ need to start writing @property definitions in the
3433
// class doc if they don't get `get` methods.
35-
if ($reflection->implementsInterface('Drupal\Core\Entity\ContentEntityInterface')) {
34+
if ($classReflection->implementsInterface('Drupal\Core\Entity\ContentEntityInterface')) {
3635
// @todo revisit if it's a good idea to be true.
3736
// Content entities have magical __get... so it is kind of true.
3837
return true;
3938
}
40-
if (self::classObjectIsSuperOfInterface($reflection, self::getFieldItemListInterfaceObject())->yes()) {
39+
if (self::classObjectIsSuperOfInterface($classReflection->getName(), self::getFieldItemListInterfaceObject())->yes()) {
4140
return FieldItemListPropertyReflection::canHandleProperty($classReflection, $propertyName);
4241
}
4342

@@ -46,21 +45,19 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
4645

4746
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
4847
{
49-
$reflection = $classReflection->getNativeReflection();
50-
if ($reflection->implementsInterface('Drupal\Core\Entity\EntityInterface')) {
48+
if ($classReflection->implementsInterface('Drupal\Core\Entity\EntityInterface')) {
5149
return new EntityFieldReflection($classReflection, $propertyName);
5250
}
53-
if (self::classObjectIsSuperOfInterface($reflection, self::getFieldItemListInterfaceObject())->yes()) {
51+
if (self::classObjectIsSuperOfInterface($classReflection->getName(), self::getFieldItemListInterfaceObject())->yes()) {
5452
return new FieldItemListPropertyReflection($classReflection, $propertyName);
5553
}
5654

5755
throw new \LogicException($classReflection->getName() . "::$propertyName should be handled earlier.");
5856
}
5957

60-
public static function classObjectIsSuperOfInterface(\ReflectionClass $reflection, ObjectType $interfaceObject) : TrinaryLogic
58+
public static function classObjectIsSuperOfInterface(string $name, ObjectType $interfaceObject) : TrinaryLogic
6159
{
62-
$classObject = new ObjectType($reflection->getName());
63-
return $interfaceObject->isSuperTypeOf($classObject);
60+
return $interfaceObject->isSuperTypeOf(new ObjectType($name));
6461
}
6562

6663
protected static function getFieldItemListInterfaceObject() : ObjectType

src/Rules/Drupal/PluginManager/AbstractPluginManagerRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace mglaman\PHPStanDrupal\Rules\Drupal\PluginManager;
44

5+
use PHPStan\Reflection\ClassReflection;
56
use PHPStan\Rules\Rule;
67

78
/**
@@ -10,7 +11,7 @@
1011
abstract class AbstractPluginManagerRule implements Rule
1112
{
1213

13-
protected function isPluginManager(\ReflectionClass $classReflection): bool
14+
protected function isPluginManager(ClassReflection $classReflection): bool
1415
{
1516
return
1617
!$classReflection->isInterface() &&

src/Rules/Drupal/PluginManager/PluginManagerSetsCacheBackendRule.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public function processNode(Node $node, Scope $scope): array
4242
throw new ShouldNotHappenException();
4343
}
4444

45-
$classReflection = $scopeClassReflection->getNativeReflection();
46-
47-
if (!$this->isPluginManager($classReflection)) {
45+
if (!$this->isPluginManager($scopeClassReflection)) {
4846
return [];
4947
}
5048

0 commit comments

Comments
 (0)