Skip to content

Commit b564ca4

Browse files
VincentLangletondrejmirtes
authored andcommitted
Handle SimpleXMLElement in VariablePropertyFetchRule
1 parent daeec74 commit b564ca4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Rules/VariableVariables/VariablePropertyFetchRule.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
1212
use PHPStan\Type\VerbosityLevel;
13+
use SimpleXMLElement;
1314
use function sprintf;
1415

1516
/**
@@ -50,7 +51,11 @@ public function processNode(Node $node, Scope $scope): array
5051
continue;
5152
}
5253

53-
if ($this->isUniversalObjectCrate($this->reflectionProvider->getClass($referencedClass))) {
54+
$classReflection = $this->reflectionProvider->getClass($referencedClass);
55+
if (
56+
$this->isUniversalObjectCrate($classReflection)
57+
|| $this->isSimpleXMLElement($classReflection)
58+
) {
5459
return [];
5560
}
5661
}
@@ -63,6 +68,14 @@ public function processNode(Node $node, Scope $scope): array
6368
];
6469
}
6570

71+
private function isSimpleXMLElement(
72+
ClassReflection $classReflection
73+
): bool
74+
{
75+
return $classReflection->getName() === SimpleXMLElement::class
76+
|| $classReflection->isSubclassOf(SimpleXMLElement::class);
77+
}
78+
6679
private function isUniversalObjectCrate(
6780
ClassReflection $classReflection
6881
): bool

tests/Rules/VariableVariables/VariablePropertyFetchRuleTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ protected function getRule(): Rule
1515
{
1616
return new VariablePropertyFetchRule($this->createReflectionProvider(), [
1717
'stdClass',
18-
'SimpleXMLElement',
1918
]);
2019
}
2120

@@ -29,4 +28,9 @@ public function testRule(): void
2928
]);
3029
}
3130

31+
public function testBug243(): void
32+
{
33+
$this->analyse([__DIR__ . '/data/bug243.php'], []);
34+
}
35+
3236
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Bug243;
4+
5+
function test(\SimpleXMLElement $xml) {
6+
$xml->{'foo-bar'};
7+
};

0 commit comments

Comments
 (0)