1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
Commit Graph

10955 Commits

Author SHA1 Message Date
orklah
0b790e0982
Merge pull request #8427 from staabm/attr
added SensitiveParameter, AllowDynamicProperties php 8.2 attributes
2022-08-22 19:15:07 +02:00
Markus Staab
72a1c05717
Restore CliUtils.php 2022-08-22 16:59:27 +02:00
Markus Staab
198347fac7 fix test 2022-08-22 16:58:23 +02:00
Markus Staab
8407cacc02 improve CI error message 2022-08-22 16:55:32 +02:00
Markus Staab
a3d58cf2fd imports 2022-08-22 16:55:26 +02:00
Markus Staab
63915d1e2c added SensitiveParameter, AllowDynamicProperties php 8.2 attributes 2022-08-22 16:44:55 +02:00
orklah
91705722ff
Merge pull request #8424 from krsriq/fix_typo
Fix doc typos
2022-08-21 00:13:55 +02:00
Daniel Schmelz
9c67b85f39
Fix typos 2022-08-20 23:29:03 +02:00
orklah
7ee3a81bce
Merge pull request #8370 from someniatko/issue-8363
Ensure we recognize inherited static methods for the first-class callables
2022-08-18 21:50:20 +02:00
orklah
0d0a049eb2
Merge pull request #8405 from vjik/get-modifiers-name
Clarification of `Reflection::getModifierNames()` result type
2022-08-12 18:53:47 +02:00
orklah
24b8b8e6ce
Merge pull request #8403 from paulfedorow/imageinterlace-callmap-fix-4.x
Fix `imageinterlace` function signature
2022-08-12 18:29:19 +02:00
Sergei Predvoditelev
4498a523b9
fix 2022-08-12 16:12:36 +03:00
Sergei Predvoditelev
ffe4375a60
Clarification of Reflection::getModifierNames() result type 2022-08-12 16:03:56 +03:00
Paul Fedorow
8908638219 Fix imageinterlace function signature 2022-08-12 11:22:45 +02:00
orklah
7e010a7a4f
Merge pull request #8372 from kkmuffme/safely-read-write-cache-data
always use lock when writing/reading cache data to/from file
2022-08-11 18:06:56 +02:00
orklah
28f22c7b57
Merge pull request #8400 from staabm/truthy
added truthy-string alias for non-falsy-string
2022-08-11 17:35:58 +02:00
Markus Staab
8f6e16add6 added truthy-string alias for non-falsy-string 2022-08-11 16:49:58 +02:00
kkmuffme
8ca594a34d always use lock when writing/reading cache data to/from file 2022-08-11 13:12:47 +02:00
AndrolGenhald
aae539560b
Merge pull request #8376 from Daeroni/fix-8373
Use classlike_storage_provider only if it has the required data
2022-08-08 16:01:49 -05:00
Teemu Koskinen
89b7b3234b
Add test for #8373
Undefined classes in function dockblocks should not crash psalm.
Test provided by @AndrolGenhald
2022-08-08 23:49:14 +03:00
Teemu Koskinen
fefd4861d6
Use $codebase->classlike_storage_provider only if it has the required data. Fixes #8373 2022-08-08 23:49:14 +03:00
orklah
57fcc3968e
Merge pull request #8350 from Ocramius/fix/datetime-constructor-is-not-immutable
Added better stubs for `DateTimeImmutable`, highlighting how the constructor is **NOT** immutable
2022-08-07 22:57:43 +02:00
Marco Pivetta
13828771c7 Removed DateTimeImmutable::createFromInterface() from stubs
While there is value in declaring `DateTimeImmutable::createFromInterface()` as mutation-free in
a stub, this method was introduced in PHP 8.0, so we cannot really declare it in a stub.

For now, we drop it, as the value of its stub declaration is much lower than the problems it
introduces through its conditional existence.
2022-08-05 13:28:53 +02:00
Marco Pivetta
68ffae097e Simplified DateTimeImmutable::format(): always returns a string
Also:

 * a non-empty format string will always lead to `non-empty-string`
 * it seems that you can throw **everything** at `DateTimeInterface#format()`, even null bytes,
   and it will always produce a `string`
2022-08-05 13:21:28 +02:00
Marco Pivetta
a1ed84f1ed Removed DateTimeImmutable::createFromMutable() from the CallMap: fully covered by stub 2022-08-05 12:52:32 +02:00
Marco Pivetta
aaac9ccb90 Removed DateTimeImmutable::setTimestamp() from the CallMap: fully covered by stub
Also simplified the return type from `static|false` to `static`, since
the method throws at all times, on failure.

On PHP 7.x, it could only fail if an invalid type was passed in, which is
not really valid anyway, from a type perspective.

Ref (PHP 8.1.x): 32d55f7422/ext/date/php_date.c (L3353-L3369)
Ref (PHP 7.0.33): bf574c2b67/ext/date/php_date.c (L3596-L3612)
2022-08-05 12:50:51 +02:00
Marco Pivetta
964f64a500 Removed DateTimeImmutable::setISODate() from the CallMap: fully covered by stub
Also simplified the return type from `static|false` to `static`, since
the method throws at all times, on failure.

On PHP 7.x, it could only fail if an invalid type was passed in, which is
not really valid anyway, from a type perspective.

Ref (PHP 8.1.x): 32d55f7422/ext/date/php_date.c (L3308-L3324)
Ref (PHP 7.0.33): bf574c2b67/ext/date/php_date.c (L3549-L3565)
2022-08-05 12:49:45 +02:00
Marco Pivetta
0a6c9d0177 Removed DateTimeImmutable::setDate() from the CallMap: fully covered by stub
Also simplified the return type from `static|false` to `static`, since
the method throws at all times, on failure.

On PHP 7.x, it could only fail if an invalid type was passed in, which is
not really valid anyway, from a type perspective.

Ref (PHP 8.1.x): 32d55f7422/ext/date/php_date.c (L3258-L3274)
Ref (PHP 7.0.33): bf574c2b67/ext/date/php_date.c (L3496-L3512)
2022-08-05 12:48:29 +02:00
Marco Pivetta
e61c593a2c Removed DateTimeImmutable::setTime() from the CallMap: fully covered by stub
Also simplified the return type from `static|false` to `static`, since
the method throws at all times, on failure.

On PHP 7.x, it could only fail if an invalid type was passed in, which is
not really valid anyway, from a type perspective.

Ref (PHP 8.1.x): 32d55f7422/ext/date/php_date.c (L3212-L3228)
Ref (PHP 7.0.33): bf574c2b67/ext/date/php_date.c (L3447-L3463)
2022-08-05 12:47:04 +02:00
Marco Pivetta
4fe554d6d2 Removed DateTimeImmutable::setTimezone() from the CallMap: fully covered by stub
Also simplified the return type from `static|false` to `static`, since
the method throws at all times, on failure.

On PHP 7.x, it could only fail if an invalid type was passed in, which is
not really valid anyway, from a type perspective.

Ref (PHP 8.2.x): 534127d3b2/ext/date/php_date.c (L3291-L3307)
Ref (PHP 8.2.x): 534127d3b2/ext/date/php_date.stub.php (L517-L518)
Ref (PHP 7.0.33): bf574c2b67/ext/date/php_date.c (L3363-L3379)
2022-08-05 12:42:45 +02:00
Marco Pivetta
cb9939cbd3 Removed DateTimeImmutable::add() from the CallMap: fully covered by stub
Ref: 534127d3b2/ext/date/php_date.stub.php (L511-L512)
Ref: 534127d3b2/ext/date/php_date.c (L3129-L3144)
2022-08-05 12:39:16 +02:00
Marco Pivetta
7cd3d49dc4 Removed DateTimeImmutable::modify() from the CallMap: fully covered by stub
Also expanded the return type from `static` to `static|false`, since the
operation can fail (with a warning too), such as in following example:

https://3v4l.org/Xrjlc

```php
<?php

var_dump(
    (new DateTimeImmutable())
        ->modify('potato')
);
```

Produces

```
Warning: DateTimeImmutable::modify(): Failed to parse time string (potato) at position 0 (p): The timezone could not be found in the database in /in/Xrjlc on line 6
bool(false)
```

Ref: 534127d3b2/ext/date/php_date.stub.php (L508-L509)
2022-08-05 12:37:24 +02:00
Marco Pivetta
18557b8c70 Removed DateTimeImmutable::diff() from the CallMap: fully covered by stub 2022-08-05 12:34:31 +02:00
Marco Pivetta
002585b57e Removed DateTimeImmutable::getTimestamp() from the CallMap: fully covered by stub
This also simplifies the return type from `int|false` to always `int`,
since a timestamp can always be produced.

Ref: eff9aed159/ext/date/php_date.stub.php (L496-L500)
2022-08-05 12:32:26 +02:00
Marco Pivetta
1be04e0988 Removed DateTimeImmutable::getOffset() from the CallMap: fully covered by stub 2022-08-05 12:27:29 +02:00
Marco Pivetta
2b6fddf88d Removed DateTimeImmutable::getTimezone() from the CallMap: fully covered by stub
Note: also verified that a `DateTimeImmutable#getTimezone()` always returns
a default timezone (initialized internally), and therefore restricted the
type a bit.
2022-08-05 12:26:59 +02:00
Marco Pivetta
7ee12c7493 Removed DateTimeImmutable::format() from the CallMap: fully covered by stub
Note: some conditional return type magic was required here.

See: https://github.com/vimeo/psalm/pull/8350#discussion_r937089212
2022-08-05 12:24:35 +02:00
Marco Pivetta
58ca4e0b73 Removed DateTimeImmutable::createFromFormat() from the CallMap: fully covered by stub 2022-08-05 12:23:43 +02:00
Marco Pivetta
267d76088d Removed DateTimeImmutable::sub() from the CallMap: fully covered by stub 2022-08-05 12:23:00 +02:00
Marco Pivetta
dc7d26abb1 Removed DateTimeImmutable::__construct from the CallMap: fully covered by stub 2022-08-05 12:22:27 +02:00
someniatko
be02e7e5c7 #8363 - support static as a type parameter in return types of the first-class callables 2022-08-04 17:16:06 +03:00
someniatko
f3d67845c5 #8363 - ensure we recognize inherited static methods for the first-class callables 2022-08-04 17:01:42 +03:00
orklah
1ef3851580
Merge pull request #8364 from kkmuffme/add-but-to-differentiate-errors-invalidargument
add ", but" for InvalidArgument error message where a type is provided
2022-08-03 20:33:29 +02:00
kkmuffme
d2be169ce5 update tests 2022-08-03 20:12:18 +02:00
kkmuffme
0d32203f9a add ", but" for InvalidArgument error message where a type is provided 2022-08-03 19:40:30 +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
c205d652d1 DateTimeImmutable#sub() always returns another static instance, never false 2022-07-31 18:12:07 +02:00
Marco Pivetta
dcaf610b0a Removed @psalm-immutable marked from MyDate extending DateTimeImmutable
`DateTimeImmutable` is not really immutable, therefore this marker was wrong upfront
2022-07-31 18:08:01 +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
orklah
6998fabb2b
Merge pull request #8349 from VincentLanglet/formatCurrency
Fix formatCurrency return type
2022-07-31 15:10:26 +02:00