1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 01:09:38 +01:00

Merge pull request #6505 from orklah/DomDocumentProperties

add PropertyTypeProvider for DomDocument
This commit is contained in:
Bruce Weirdan 2021-09-18 14:05:57 +03:00 committed by GitHub
commit 3082a82a21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -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);
}
/**

View File

@ -0,0 +1,31 @@
<?php declare(strict_types=1);
namespace Psalm\Internal\Provider\PropertyTypeProvider;
use Psalm\Plugin\EventHandler\Event\PropertyTypeProviderEvent;
use Psalm\Plugin\EventHandler\PropertyTypeProviderInterface;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNull;
use Psalm\Type\Union;
use function strtolower;
class DomDocumentPropertyTypeProvider implements PropertyTypeProviderInterface
{
public static function getPropertyType(PropertyTypeProviderEvent $event): ?Union
{
if (strtolower($event->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'];
}
}