1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

feature: ensure universal object crate class exists (#4375)

This commit is contained in:
feek 2020-10-20 14:17:49 -07:00 committed by Daniil Gentili
parent 7df404bfb5
commit d1b7cf6860
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 8 additions and 12 deletions

View File

@ -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;
}

View File

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

View File

@ -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;