mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 09:19:40 +01:00
Merge pull request #6505 from orklah/DomDocumentProperties
add PropertyTypeProvider for DomDocument
This commit is contained in:
commit
3082a82a21
@ -2,6 +2,7 @@
|
|||||||
namespace Psalm\Internal\Provider;
|
namespace Psalm\Internal\Provider;
|
||||||
|
|
||||||
use Psalm\Context;
|
use Psalm\Context;
|
||||||
|
use Psalm\Internal\Provider\PropertyTypeProvider\DomDocumentPropertyTypeProvider;
|
||||||
use Psalm\Plugin\EventHandler\Event\PropertyTypeProviderEvent;
|
use Psalm\Plugin\EventHandler\Event\PropertyTypeProviderEvent;
|
||||||
use Psalm\Plugin\EventHandler\PropertyTypeProviderInterface;
|
use Psalm\Plugin\EventHandler\PropertyTypeProviderInterface;
|
||||||
use Psalm\Plugin\Hook\PropertyTypeProviderInterface as LegacyPropertyTypeProviderInterface;
|
use Psalm\Plugin\Hook\PropertyTypeProviderInterface as LegacyPropertyTypeProviderInterface;
|
||||||
@ -39,6 +40,8 @@ class PropertyTypeProvider
|
|||||||
{
|
{
|
||||||
self::$handlers = [];
|
self::$handlers = [];
|
||||||
self::$legacy_handlers = [];
|
self::$legacy_handlers = [];
|
||||||
|
|
||||||
|
$this->registerClass(DomDocumentPropertyTypeProvider::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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'];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user