1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/stubs
Marco Pivetta b4b2bc66c7 Added better stubs for DateTimeImmutable, highlighting how the constructor is **NOT** immutable
`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);
```
2022-07-31 18:02:30 +02:00
..
CoreGenericClasses.phpstub Allow null to ArrayAccess::offsetSet $offset param 2022-03-06 13:47:32 +01:00
CoreGenericFunctions.phpstub Fix nullable return types for CallMap functions 2022-07-13 22:44:38 -05:00
CoreGenericIterators.phpstub Fix #6464: false positive for RecursiveArrayIterator::CHILD_ARRAYS_ONLY 2021-09-09 11:12:24 +02:00
CoreImmutableClasses.phpstub Added better stubs for DateTimeImmutable, highlighting how the constructor is **NOT** immutable 2022-07-31 18:02:30 +02:00
decimal.phpstub Allow operator overloading for Decimal extension (fixes #3938). 2021-12-08 10:59:37 -06:00
DOM.phpstub Fix SimpleXMLIterator historic and current signatures 2021-08-16 00:04:59 +03:00
ext-apcu.phpstub bugfix/#7912: Add Iterator implements to stub 2022-05-17 23:55:44 +02:00
ext-ds.phpstub Add Set::map() to ext-ds stub 2021-12-14 10:19:08 +01:00
ext-geos.phpstub Rename stub to avoid phpstorm conflict (#5213) 2021-02-13 18:42:34 -05:00
mongodb.phpstub Add mongodb Cursor and CursorInterface stubs and fix WriteConcern::__construct (#5813) 2021-05-22 19:03:07 -04:00
mysqli.phpstub typo 2021-12-29 16:56:09 +01:00
pdo.phpstub pdo: more precise generic type 2022-01-03 17:11:03 +01:00
Php80.phpstub Code style 2022-07-25 17:15:28 +03:00
Php81.phpstub Update stub 2022-02-23 00:52:53 +02:00
phpparser.phpstub ->args to ->getArgs 2021-10-09 23:37:04 +02:00
phpredis.phpstub update phpredis stubs 2022-03-04 12:56:30 +01:00
Reflection.phpstub Fix return type of ReflectionNamedType::getName() 2022-06-29 18:22:46 +02:00
soap.phpstub Update signatures of methods of SoapClient 2021-12-12 19:43:06 +03:00
SPL.phpstub Fix invalid class/method declaration in stub 2021-10-05 21:41:27 +09:00
Xdebug.phpstub Rename stub to avoid phpstorm conflict (#5213) 2021-02-13 18:42:34 -05:00