Skip to content

Commit 02277ce

Browse files
committed
Merge remote-tracking branch 'origin/1.6.x' into 2.0.x
2 parents ed6fea0 + b564ca4 commit 02277ce

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
/**
@@ -49,7 +50,11 @@ public function processNode(Node $node, Scope $scope): array
4950
continue;
5051
}
5152

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

70+
private function isSimpleXMLElement(
71+
ClassReflection $classReflection
72+
): bool
73+
{
74+
return $classReflection->getName() === SimpleXMLElement::class
75+
|| $classReflection->isSubclassOf(SimpleXMLElement::class);
76+
}
77+
6578
private function isUniversalObjectCrate(
6679
ClassReflection $classReflection
6780
): 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)