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

9 Commits

Author SHA1 Message Date
Marco Pivetta
267d76088d Removed DateTimeImmutable::sub() from the CallMap: fully covered by stub 2022-08-05 12:23:00 +02:00
Marco Pivetta
68978b9e19 s/psalm-pure/psalm-mutation-free, since psalm-mutation-free is safer to use
Ref: c205d652d1 (r934032422)

The idea is that `@psalm-pure` disallows `$this` usage in child classes,
which is not wanted, while `@psalm-mutation-free` allows it.

By using `@psalm-mutation-free`, we don't completely destroy inheritance
use-cases based on internal (immutable) state.
2022-08-01 10:08:35 +02:00
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
Semyon
462ce7138a Make DatePeriod implement Traversable oh PHP 7, rename constructor params 2022-07-25 17:11:36 +03:00
Semyon
9d3253482d Add stub for DatePeriod 2022-07-25 17:11:36 +03:00
hirokinoue
c6d7bc0d19 Improve Throwable::getTrace() return type 2022-04-12 23:42:37 +09:00
Ciaran McNulty
ca185d7f28 Update Throwable::getTrace in stubs 2022-03-18 09:14:37 +00:00
Tarmo Leppänen
ede95105ac
Update CoreImmutableClasses.phpstub (#5218)
Fixes wrong parameter names - https://psalm.dev/r/8cfdb309d9
2021-02-14 12:07:39 -05:00
Matt Brown
f3b05f5ab5 Move static code out of src 2020-10-12 00:59:19 -04:00