mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 22:01:48 +01:00
b4b2bc66c7
`DateTimeImmutable` is **almost** immutable: `DateTimeImmutable::__construct()` is in fact not a pure method, since `new DateTimeImmutable('now')` produces a different value at each instantiation (by design). This change makes sure that `DateTimeImmutable` loses its `@psalm-immutable` class-level marker, preventing downstream misuse of the constructor inside otherwise referentially transparent code. Note: only pure methods are stubbed here: all other methods declared by `DateTimeImmutable` (parent interface) are NOT present here, and are either inferred from runtime reflection, or `CallMap*.php` definitions. Methods are sorted in the order defined by reflection on PHP 8.1.8, at the time of writing this ( https://3v4l.org/3TGg8 ). Following simplistic snippet was used to infer the current signature: ```php <?php $c = new \ReflectionClass(\DateTimeImmutable::class); $methods = array_map(function ($m) { return $m->getName() . '(' . implode(',', array_map(function ($p) { return $p->getType() . ' $' . $p->getName() . ($p->isOptional() ? ' = ' . var_export($p->getDefaultValue(), true) : ''); }, $m->getParameters())) . ')' . ($m->getReturnType() ? (': ' . $m->getReturnType()) : ''); }, $c->getMethods()); $properties = array_map(function ($m) { return $m->getName(); }, $c->getProperties()); var_dump($methods, $properties); ```