Skip to content

Commit c5ec05a

Browse files
committed
Fix PHPStan 1.7.0 incompatibilities
1 parent c7fcb79 commit c5ec05a

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/Reflection/EntityFieldsViaMagicReflectionExtension.php

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

33
namespace mglaman\PHPStanDrupal\Reflection;
44

5+
use PHPStan\BetterReflection\Reflection\ReflectionClass;
56
use PHPStan\Reflection\ClassReflection;
67
use PHPStan\Reflection\PropertiesClassReflectionExtension;
78
use PHPStan\Reflection\PropertyReflection;
@@ -28,16 +29,15 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
2829
return false;
2930
}
3031

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

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

4747
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
4848
{
49-
$reflection = $classReflection->getNativeReflection();
50-
if ($reflection->implementsInterface('Drupal\Core\Entity\EntityInterface')) {
49+
if ($classReflection->implementsInterface('Drupal\Core\Entity\EntityInterface')) {
5150
return new EntityFieldReflection($classReflection, $propertyName);
5251
}
53-
if (self::classObjectIsSuperOfInterface($reflection, self::getFieldItemListInterfaceObject())->yes()) {
52+
if (self::classObjectIsSuperOfInterface($classReflection->getName(), self::getFieldItemListInterfaceObject())->yes()) {
5453
return new FieldItemListPropertyReflection($classReflection, $propertyName);
5554
}
5655

5756
throw new \LogicException($classReflection->getName() . "::$propertyName should be handled earlier.");
5857
}
5958

60-
public static function classObjectIsSuperOfInterface(\ReflectionClass $reflection, ObjectType $interfaceObject) : TrinaryLogic
59+
public static function classObjectIsSuperOfInterface(string $name, ObjectType $interfaceObject) : TrinaryLogic
6160
{
62-
$classObject = new ObjectType($reflection->getName());
63-
return $interfaceObject->isSuperTypeOf($classObject);
61+
return $interfaceObject->isSuperTypeOf(new ObjectType($name));
6462
}
6563

6664
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)