github vimeo/psalm 3.13.0
Allow MissingPropertyType to be fixed automatically

latest releases: 5.23.1, 5.23.0, 5.22.2...
3 years ago

Features

MissingPropertyType fixer

Running vendor/bin/psalm --alter --issues=MissingPropertyType (when using PHP 7.4) on

<?php
class A {
    public $string_or_int;
    public $only_string;
    public $conditionally_set_string;

    public function __construct()
    {
        if (rand(0, 1)) {
            $this->string_or_int = 5;
        } else {
            $this->string_or_int = "hello";
            $this->conditionally_set_string = "goodbye";
        }

        $this->only_string = "bar";
    }
}

gives

<?php
class A {
    /**
     * @var string|int
     */
    public $string_or_int;

    public string $only_string;

    /**
     * @var null|string
     */
    public $conditionally_set_string;

    public function __construct()
    {
        if (rand(0, 1)) {
            $this->string_or_int = 5;
        } else {
            $this->string_or_int = "hello";
            $this->conditionally_set_string = "goodbye";
        }

        $this->only_string = "baz";
    }
}

This fix has full compatibility with previous versions of PHP, too.

=== true detection

@greg0ire added support such that Psalm will warn you when comparing $some_bool === true where $some_bool would have sufficed.

This option is hidden behind the strictBinaryOperands config flag.

positive-int

Psalm has a new type, positive-int, for situations where you want the typechecker to guarantee that an integer is positive.

Other features

  • @TysonAndre added support for generating multiple reports from a single Psalm run (#3776, #3777)
  • Language Server: @joehoyle added jump-to-definition for use statements (#3805)
  • @ntzm added support for disabling the analysis of phpStormMeta files (#3833)
  • @bdsl improved the handling of @internal, hopefully clarifying its usage (#3841)
  • Psalm now detects impossible substr comparisons based on string length (#3877)
  • @var docblock annotations are now supported in many more places (#1916)

Bugfixes

  • fix resolution of @template T as self inside traits (#3753)
  • prevent a crash when a class being thrown is not found (#3755)
  • array_map should remember how an array was created (#3764)
  • @joehoyle improved performance when scanning large stub files (#3781)
  • Language Server: @joehoyle fixed the offset calculation in getReferenceAtPosition (#3783)
  • allow removing false and null from a templated var (#3790)
  • @erunion added support for always running taint analysis via the config (#3800)
  • allow analysis of $i++ inside an isset check (#3802)
  • prevent a large number of chained assignments crashing Psalm (#3797)
  • Language Server: @joehoyle fixed jump-to-definition for nullable function param types (#3804)
  • Language Server: @joehoyle fixed jump-to-definition for return types where the docblock type is invalid (#3806)
  • @weirdan improved Psalm's support for custom autoloader logic (#3183)
  • allow more complex negations from custom assertions (#3811)
  • allow detection of paradoxes when switching on the result of a function call (#3808)
  • @EvgeniiR improved support for array_column such that it can understand emptiness (#3813)
  • @TysonAndre added more impure function references (#3814)
  • improved a bunch of things around how getters are treated (#3820, #3825 and more)
  • @ntzm made the *getcsv return types more specific (#3832)
  • @adrienlucas added taint tracking through strval and sprintf
  • @ygottschalk improved handling of key, array_key_first and array_key_last (#3838)
  • @EvgeniiR fixed an erroneous UndefinedClass issue that could crop up with params of type array|callable (#3842)
  • @gharlan added support for assignments to immutable classes in __unserialize (#3845)
  • improve support for falsy assertions (#3858)
  • allow magic properties to be reconciled just like regular properties (#3857)
  • detect mutations due to property assignments in mutation-free methods (#3870)
  • prevent a crash when comparing an object with properties to a missing class (#3882)
  • don't alter a class-string type when doing an empty check (#3894)
  • support turning methods final via trait aliasing (#3897)
  • allow templated types to be refined via instanceof (#3907)

Don't miss a new psalm release

NewReleases is sending notifications on new releases.