diff --git a/src/Psalm/Internal/Provider/PropertyTypeProvider.php b/src/Psalm/Internal/Provider/PropertyTypeProvider.php index 02e1d40ec..af3052514 100644 --- a/src/Psalm/Internal/Provider/PropertyTypeProvider.php +++ b/src/Psalm/Internal/Provider/PropertyTypeProvider.php @@ -2,6 +2,7 @@ namespace Psalm\Internal\Provider; use Psalm\Context; +use Psalm\Internal\Provider\PropertyTypeProvider\DomDocumentPropertyTypeProvider; use Psalm\Plugin\EventHandler\Event\PropertyTypeProviderEvent; use Psalm\Plugin\EventHandler\PropertyTypeProviderInterface; use Psalm\Plugin\Hook\PropertyTypeProviderInterface as LegacyPropertyTypeProviderInterface; @@ -39,6 +40,8 @@ class PropertyTypeProvider { self::$handlers = []; self::$legacy_handlers = []; + + $this->registerClass(DomDocumentPropertyTypeProvider::class); } /** diff --git a/src/Psalm/Internal/Provider/PropertyTypeProvider/DomDocumentPropertyTypeProvider.php b/src/Psalm/Internal/Provider/PropertyTypeProvider/DomDocumentPropertyTypeProvider.php new file mode 100644 index 000000000..f49d952dc --- /dev/null +++ b/src/Psalm/Internal/Provider/PropertyTypeProvider/DomDocumentPropertyTypeProvider.php @@ -0,0 +1,31 @@ +getPropertyName()) === 'documentelement') { + $type = new Union([new TNamedObject('DOMElement'), new TNull()]); + $type->ignore_nullable_issues = true; + + return $type; + } + + return null; + } + + public static function getClassLikeNames(): array + { + return ['domdocument']; + } +}