mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +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)) {
|
if (isset($config_xml->universalObjectCrates) && isset($config_xml->universalObjectCrates->class)) {
|
||||||
/** @var \SimpleXMLElement $universal_object_crate */
|
/** @var \SimpleXMLElement $universal_object_crate */
|
||||||
foreach ($config_xml->universalObjectCrates->class as $universal_object_crate) {
|
foreach ($config_xml->universalObjectCrates->class as $universal_object_crate) {
|
||||||
/** @var class-string $classString */
|
/** @var string $classString */
|
||||||
$classString = $universal_object_crate['name'];
|
$classString = $universal_object_crate['name'];
|
||||||
$config->addUniversalObjectCrate($classString);
|
$config->addUniversalObjectCrate($classString);
|
||||||
}
|
}
|
||||||
@ -2007,11 +2007,11 @@ class Config
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param class-string $class
|
|
||||||
*/
|
|
||||||
public function addUniversalObjectCrate(string $class): void
|
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;
|
$this->universal_object_crates[] = $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,12 +1300,12 @@ class ConfigTest extends \Psalm\Tests\TestCase
|
|||||||
'<?xml version="1.0"?>
|
'<?xml version="1.0"?>
|
||||||
<psalm>
|
<psalm>
|
||||||
<universalObjectCrates>
|
<universalObjectCrates>
|
||||||
<class name="Foo" />
|
<class name="DateTime" />
|
||||||
</universalObjectCrates>
|
</universalObjectCrates>
|
||||||
</psalm>'
|
</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
|
public function testUniversalObjectCrates(): void
|
||||||
{
|
{
|
||||||
/** @var class-string $classString */
|
Config::getInstance()->addUniversalObjectCrate(\DateTime::class);
|
||||||
$classString = 'Foo';
|
|
||||||
Config::getInstance()->addUniversalObjectCrate($classString);
|
|
||||||
|
|
||||||
$this->addFile(
|
$this->addFile(
|
||||||
'somefile.php',
|
'somefile.php',
|
||||||
'<?php
|
'<?php
|
||||||
class Foo { }
|
$f = new \DateTime();
|
||||||
|
|
||||||
$f = new Foo();
|
|
||||||
// reads are fine
|
// reads are fine
|
||||||
$f->bar;
|
$f->bar;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user