Skip to content

Commit befb743

Browse files
committed
Fix SimpleXMLElement iterable type on PHP 8
1 parent af5921e commit befb743

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"ondram/ci-detector": "^3.4.0",
2626
"ondrejmirtes/better-reflection": "4.3.37",
2727
"phpdocumentor/reflection-docblock": "4.3.4",
28-
"phpstan/php-8-stubs": "^0.1.4",
28+
"phpstan/php-8-stubs": "^0.1.5",
2929
"phpstan/phpdoc-parser": "^0.4.9",
3030
"react/child-process": "^0.6.1",
3131
"react/event-loop": "^1.1",

composer.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/functionMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10239,7 +10239,7 @@
1023910239
'SimpleXMLElement::getNamespaces' => ['string[]', 'recursive='=>'bool'],
1024010240
'SimpleXMLElement::registerXPathNamespace' => ['bool', 'prefix'=>'string', 'ns'=>'string'],
1024110241
'SimpleXMLElement::xpath' => ['SimpleXMLElement[]|false', 'path'=>'string'],
10242-
'SimpleXMLIterator::current' => ['SimpleXMLIterator|null'],
10242+
'SimpleXMLIterator::current' => ['SimpleXMLIterator'],
1024310243
'SimpleXMLIterator::getChildren' => ['SimpleXMLIterator'],
1024410244
'SimpleXMLIterator::hasChildren' => ['bool'],
1024510245
'SimpleXMLIterator::key' => ['string|false'],

src/Type/Php/SimpleXMLElementClassPropertyReflectionExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SimpleXMLElementClassPropertyReflectionExtension implements PropertiesClas
1313

1414
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
1515
{
16-
return $classReflection->getName() === 'SimpleXMLElement';
16+
return $classReflection->getName() === 'SimpleXMLElement' || $classReflection->isSubclassOf('SimpleXMLElement');
1717
}
1818

1919

tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,11 @@ public function testMixin(): void
422422
]);
423423
}
424424

425+
public function testBug3947(): void
426+
{
427+
$this->checkThisOnly = false;
428+
$this->checkUnionTypes = true;
429+
$this->analyse([__DIR__ . '/data/bug-3947.php'], []);
430+
}
431+
425432
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bug3947;
4+
5+
class HelloWorld
6+
{
7+
public function sayHello(\SimpleXMLElement $item): void
8+
{
9+
foreach ($item->items->children() as $groupItem) {
10+
switch ((string)$groupItem->orderType) {
11+
}
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)