Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Rules/VariableVariables/VariablePropertyFetchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\VerbosityLevel;
use SimpleXMLElement;
use function sprintf;

/**
Expand Down Expand Up @@ -50,7 +51,11 @@ public function processNode(Node $node, Scope $scope): array
continue;
}

if ($this->isUniversalObjectCrate($this->reflectionProvider->getClass($referencedClass))) {
$classReflection = $this->reflectionProvider->getClass($referencedClass);
if (
$this->isUniversalObjectCrate($classReflection)
|| $this->isSimpleXMLElement($classReflection)
) {
return [];
}
}
Expand All @@ -63,6 +68,14 @@ public function processNode(Node $node, Scope $scope): array
];
}

private function isSimpleXMLElement(
ClassReflection $classReflection
): bool
{
return $classReflection->getName() === SimpleXMLElement::class
|| $classReflection->isSubclassOf(SimpleXMLElement::class);
}

private function isUniversalObjectCrate(
ClassReflection $classReflection
): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ protected function getRule(): Rule
{
return new VariablePropertyFetchRule($this->createReflectionProvider(), [
'stdClass',
'SimpleXMLElement',
]);
}

Expand All @@ -29,4 +28,9 @@ public function testRule(): void
]);
}

public function testBug243(): void
{
$this->analyse([__DIR__ . '/data/bug243.php'], []);
}

}
7 changes: 7 additions & 0 deletions tests/Rules/VariableVariables/data/bug243.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Bug243;

function test(\SimpleXMLElement $xml) {
$xml->{'foo-bar'};
};
Loading