Changelog History
Page 2
-
v3.18.2 Changes
October 20, 2020π Last night's release added a regression in how variables set in try statements are treated, ticketed here: #4368
-
v3.18.0 Changes
October 19, 2020Language server works again
π This fixes an issue that prevented the language server from seeing recent changes to files (caused, almost inexplicably, by removing a
@param
docblock).π Other bugfixes
- π Fix an issue with remapped template params (#4326)
- π Improve handling of
try
statements without catches (#4333, #4366) - Deal with a few more combinatorial expansion issues gracefully (#4347)
- π Improve Psalter replacements (#4350, #4349)
- π @pascalheidmann fixed an error when creating a report in a non-existent directory (#4353)
- π Improve handling of assignments on the RHS of
||
if conditionals (#4354)
-
v3.17.2 Changes
October 15, 2020 -
v3.17.1 Changes
October 13, 2020π 3.17.0 added a potentially-erroneous return type when a non-zero
$flags
param is passed topreg_split
. This fixes things. -
v3.17.0 Changes
October 12, 2020π Features
- π§ @mr-feek added support for configurable universal objects (#3948)
- π Improved error messages and reporting for
ParadoxicalCondition
(example) β thanks to @dkarlovi, @jbafford and @ro0NL for their input
π Bugfixes
π Fixed XML generation
π 3.16 broke XML output, this is now fixed (#4252).
π Other bugfixes
- π @DanielBadura added a stub for
random_int
, providing better inference (#4199) - Improved signatures for
preg_match_all
(#4202) and @orklah helped improvepreg_split
- Treat
func_num_args
as pure (#4215) - π Fix
__invoke
declaration crash (#4210) - π Allow hinting arrow function return types (#4209)
- β Add checks for
if ((bool) $foo)
(#4206) - π Fix crash with some class-string property assignments (#4198)
- π @aheart fixed bugs with JUnit generation (#4234)
- @danog added a bunch of stubs for
Spl*
classes (#4255) - π
allowMissingFiles
was fixed by @ddeboer (#4259) - prevent crash after analysing file that defines a class twice (#4264)
- prevent an infinite loop when analysing a closure unioned with invokable class (#4266)
- @marcosh added more stubs for array functions (#4271)
- prevent crash when annotating the intersection of arrays (#4287)
- π Fix reported property id for multiple
MissingConstructor
issues on a single class (#4297) - Prevent crash when trying to negate a
positive-numeric
assertion (#4306) - π Fix return types for a few callmap-provided functions (#4309)
- Prevent a class name validation check on a string argument to a
class-string|Foo
union (#4310)
π Also thanks to @orklah for many linting PRs, and to @weirdan for very good triaging
-
v3.16 Changes
September 15, 2020π Features
π New PHPStorm-optimised output format
β Added a
phpstorm
report format that displays errors in a manner that PHPStorm can parse more easily (#4085) β thanks @the-toster (with additional help from @Rarst)Detection of
strpos
issuesPsalm will now raise two separate issues for the following code:
function foo(string $s) : void { if (strpos(".", $s) !== -1) {} }
The first,
InvalidLiteralArgument
, complains a string was passed where a variable was expected. The second complains that the output ofstrpos
can never be negative.π Allow intersection of object-like arrays and regular arrays
Psalm now allows the docblock
array{foo: string}&array<string, string>
, understanding it to mean an array of strings with one explicit known key.@psalm-stub-override
β Added support for
@psalm-stub-override
which only renders the stub valid if the given class already exists β thanks @weirdan (#4177)@psalm-suppress Issue1, Issue2
β Added support for multiple suppressed issues on a given line β thanks @weirdan (#4179)
π Bugfixes
π Allow multiple issues of the same type at a single position
β‘οΈ Psalm will now report multiple issues that map to the same code position (but whose message body is different). If you use the baseline, you might need to update it accordingly (#4167)
π Other bugfixes
- π allow slashes in docblock tags (#4112)
- ensure calling
Closure::__invoke
doesn't break when running Psalm in PHP 7.2.11 and below (#4111) - refine closure types more accurately according to a callable
- prevent crash when suppressing
UndefinedTrait
(#4130) - improve inference of
preg_match_all
$matches
array value (#4128) - π fix a crash when using a short closure without specifying the
Closure
type anywhere in the affected methods (#4148) - π allow null checks on the output of
Iterator::current
(#4146) - Language Server @matthijskooijman made a couple of improvements (#4143)
- treat literal numeric strings as
numeric
always (#4154) - Taint analysis @craigfrancis added additional mysql sinks (#4155)
- Language Server @ngyuki fixed a bug using the Phar (#4174)
- π Fix Psalm's assertion generation from
count($arr) <= 1
(#4169) - @ygottschalk improved Psalm's assertion generation from
count
calls further (#4175) - π Improve error message (and location) for unused params once they've been written to (#4127)
- prevent an empty docblock from suppressing missing property types (#4178)
- properly detect
yield
expressions in function arguments (#4122) - π improved Psalm's understanding of
array_merge
andarray_filter
functions
-
v3.15 Changes
September 01, 2020π Features
π This release brings a couple of features that are useful to fans of functional programming.
If you're unfamiliar with these concepts, or want to know how Psalm uses them, read this article first.
Automatic addition of
@psalm-pure
/@psalm-immutable
annotations (#4036):β Running
vendor/bin/psalm --alter --issues=MissingPureAnnotation,MissingImmutableAnnotation
will add those annotations to any function, method or class that deserves it.So
function sayHello(string $s): string { return 'Hello ' . $s; }
is transformed into
/\*\* \* @psalm-pure \*/function sayHello(string $s): string { return 'Hello ' . $s; }
Note : running this command will not recursively add annotations, so if you have a chain of callers like
function one(string $s) { return two($s); }function two(string $s) { return $s; }
β running the command once will produce
function one(string $s) { return two($s); }/\*\* \* @psalm-pure \*/function two(string $s) { return $s; }
and running it a second time will produce
/\*\* \* @psalm-pure \*/function one(string $s) { return two($s); }/\*\* \* @psalm-pure \*/function two(string $s) { return $s; }
Pure callables and closures
Thanks to @azjezz, Psalm now understands the annotation
pure-callable
, which allows you to guarantee the purity of a pure function that executes a callable.Let's say we want to return the longest string in an array of strings
["a", "bbb", "cc"]
. We could write that function pretty simply, but let's suppose we want to make it a bit more generic: given an array of items, and acallable
that returns a score for the each entry, return the highest-scoring value.We can define that function in PHP like
/\*\* \* @psalm-param non-empty-array $values \* @psalm-pure \*/function get\_max(array $values, callable $score\_func) { $max = reset($values); $max\_num = null; foreach ($values as $value) { $value\_num = $score\_func($value); if (null === $max\_num || $value\_num \>= $max\_num) { $max = $value; $max\_num = $value\_num; } } return $max; }echo get\_max(['a', 'bbb', 'cc'], 'strlen'); // outputs "bbb"
This function is only pure, though, if the callable that we're passing is pure.
β With this latest version the full, pure type signature of the function can be written:
/\*\* \* @template T \* @psalm-param non-empty-array\<T\> $values \* @psalm-param pure-callable(T):int $score\_func \* @psalm-return T \* \* @psalm-pure \*/function get\_max(array $values, callable $score\_func) { ... }
π Bugfixes
- preserve intersections when expanding templated types (#4043)
- π don't remove null types unnecessarily in mixed union, and refine iterable keys after
is_array
check (#4038) - assume most iterators are impure (#4064)
- π¨ process indirect comparisons to
null
in assertions (#4061) - π allow pure functions to return impure closures (#4077)
- π allow literal reconciliation against
positive-int
types (#4081, #4093) - π allow
ParamNameMismatch
to be suppressed locally (#4012) - π fix parsing of union param types inside docblock
@method
annotations(#4083) - @staabm added a slightly-improved return type for
strpos
that precludes negative numbers - π @weirdan fixed #3869 by creating a per-user cache directory
MissingPropertyType
can now be refined on a per-property basis (#2200)- @lhchavez broadened the param type for
strval
to allownull
-
v3.14.2 Changes
August 22, 2020π Bugfixes
- π Fix exception when two mixins declare the same method (seen frequently on Laravel, thanks @xyng) β #4013
- Prevent mixed assignment in loop after positive check (#4011)
- π Allow
@psalm-type
to reference imported type right above (#3999) - π Fixed some
hash_*
function signatures - thanks @baukevdw (#4014) - π Allow
float
defaults in namespaced class@method
docblock annotations (#4017) - Taint analysis - added sinks for
pgsql
functions - thanks @TysonAndre (#4021) - Resolve type aliases in
foreach
docblock annotations - thanks @weirdan (#4029) - Donβt hang when
pcntl_fork
is disabled - thanks @weirdan (#3951) - β Add config option to discover unused
@psalm-suppress
on every run β thanks @micheh (#3011)
-
v3.14.1 Changes
August 17, 2020π Fixes a crash with this code:
/** * @param array<int, int> $arr */ function foo(array $arr) : void { for ($i = 20; $arr[$i] === 5 && $i > 0; $i--) {} }
-
v3.14.0 Changes
August 17, 2020π Features
Named argument checks with ParamNameMismatch
π For more information, see this article.
Preventing unsafe instantiation
Psalm now warns you when calling
new $foo()
where$foo()
is a class that can be extended and where the constructor is not declaredfinal
, ornew static
where the constructor is not declaredfinal
(#3934).π For more information, see the issue page
Other features
π Bugfixes
- π fix a few false-positives around
positive-int
types (#3914) - expand
scalar-class-constant
types in a few more places (#3913, #3741) - @NicolasCARPi improved the signature for
hash_file()
(#3920) - honour arrays with
class-string
keys when appending literal classes (#3923) - @SignpostMarv marked
bscale
as impure (ref #3918) - preserve
list
-ness when assigning to a tuple inside a loop (#3928) - π fix regression with
array_shift
(#3941) - π @jarstelfox fixed the casing checker to ignore
callStatic
(#3939) - π @xyng added support for multiple mixins (#3772)
- π improved Psalm's recovery when it encounters complex boolean logic (#3932, #3954)
- @ygottschalk improved
reset
's return type - π @sasezaki fixed the treatment of generators when an explicit send type is provided (#3966)
- Language Server @ngyuki fixed file path handling on windows (#3984)
- π Use unused code config settings when running language server (#3987)
- Prevent an incorrect intersection of union types with
usort
(#3964) - Prevent crash with bad imported type reference (#3927)
- @weirdan improved handling of
@psalm-import-type
errors (#3997) - comparisons between classes and interfaces are now allowed (#3917)
- π fix a few false-positives around