mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
feature: ensure universal object crate class exists (#4375)
This commit is contained in:
parent
7df404bfb5
commit
d1b7cf6860
@ -966,7 +966,7 @@ class Config
|
||||
if (isset($config_xml->universalObjectCrates) && isset($config_xml->universalObjectCrates->class)) {
|
||||
/** @var \SimpleXMLElement $universal_object_crate */
|
||||
foreach ($config_xml->universalObjectCrates->class as $universal_object_crate) {
|
||||
/** @var class-string $classString */
|
||||
/** @var string $classString */
|
||||
$classString = $universal_object_crate['name'];
|
||||
$config->addUniversalObjectCrate($classString);
|
||||
}
|
||||
@ -2007,11 +2007,11 @@ class Config
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $class
|
||||
*/
|
||||
public function addUniversalObjectCrate(string $class): void
|
||||
{
|
||||
if (!class_exists($class, true)) {
|
||||
throw new \UnexpectedValueException($class . ' is not a known class');
|
||||
}
|
||||
$this->universal_object_crates[] = $class;
|
||||
}
|
||||
|
||||
|
@ -1300,12 +1300,12 @@ class ConfigTest extends \Psalm\Tests\TestCase
|
||||
'<?xml version="1.0"?>
|
||||
<psalm>
|
||||
<universalObjectCrates>
|
||||
<class name="Foo" />
|
||||
<class name="DateTime" />
|
||||
</universalObjectCrates>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains('foo', $this->project_analyzer->getConfig()->getUniversalObjectCrates());
|
||||
$this->assertContains('datetime', $this->project_analyzer->getConfig()->getUniversalObjectCrates());
|
||||
}
|
||||
}
|
||||
|
@ -120,16 +120,12 @@ class PropertyTypeTest extends TestCase
|
||||
|
||||
public function testUniversalObjectCrates(): void
|
||||
{
|
||||
/** @var class-string $classString */
|
||||
$classString = 'Foo';
|
||||
Config::getInstance()->addUniversalObjectCrate($classString);
|
||||
Config::getInstance()->addUniversalObjectCrate(\DateTime::class);
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo { }
|
||||
|
||||
$f = new Foo();
|
||||
$f = new \DateTime();
|
||||
// reads are fine
|
||||
$f->bar;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user