github vimeo/psalm 3.11.5

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

Features

Import @psalm-type annotations into classes

Added support for importing @psalm-type annotations from one class to another based on a suggestion from @malukenho (in #2924)

Given a class Phone that defines a @psalm-type annotation on a class:

<?php
/**
 * @psalm-type PhoneType = array{phone: string}
 */
class Phone {
    /**
     * @psalm-return PhoneType
     */
    public function toArray(): array {
        return ["phone" => "Nokia"];
    }
}

You can reference that type with the @psalm-import-type annotation:

/**
 * @psalm-import-type PhoneType from Phone
 */
class User {
    /**
     * @psalm-return PhoneType
     */
    function toArray(): array {
        return array_merge([], (new Phone)->toArray());
    }
}   

Other features

  • Psalm now detects a number of unused magic methods (e.g. __get, __set) (#3236)
  • Psalm now continues its analysis after encountering undefined variables (#3366)
  • @dereuromark added a pretty-print option for JSON output
  • Language Server: @joehoyle added variable assignment hover information (#3401)

Bugfixes

  • Prevent crashes in method type parsing (#3340), when @mixin type can't be found (#3452), when throwing an exception without a known alias (#3465), and when yielded type tokenisation fails (#3430)
  • Prevent notice due to empty function id (#3354)
  • The Phar now doesn’t prefix any Psalm classes (#3152, #2904, #2652)
  • @nobuf added support for inferring that an object can be cast after is_callable([$var, '__isString']) (#3372)
  • Psalter: @orklah added a fix that avoids updating docblocks when no changes are made (#3374)
  • @ragboyjr fixed return type inference (based on docblock return type) for arrow functions (#3376)
  • Eliminate null after > 0 check (#3388)
  • @SignpostMarv added numeric-string inference when casting a numeric type to a string (#3390)
  • @EvgeniiR helped improve analysis of possibly-correct clone expressions (#3382)
  • @orklah improved inference for array_sum (#3395)
  • Language Server: @joehoyle fixed bugs around getting symbol information for array shapes (#3400)
  • Remove possibly-undefined array keys when merging (#3393)
  • Allow conditional return types with func_num_args() in namespaces (#3423)
  • Don’t add null to return type as part of reflection when using docblock templates (#3419)
  • Allow falsy reconciliation for templated params (#3426)
  • Always treat $this as static-y (#3417)
  • Flesh out static references in Closure():static return types (#3415)
  • Prevent a function param typed with a "0"|"1" from accepting a numeric-string type (#3440)
  • Allow isset checks on undefined static properties (#3460)
  • Allow conditional return type inference with func_get_args() on instance methods (#3453)
  • @still-dreaming-1 improved plugin handling for AfterAnalysisInterface (#3461)
  • Improve handling of templated @mixin annotation (#3458)
  • Improve handling of array_key_exists checks (#3463)

Don't miss a new psalm release

NewReleases is sending notifications on new releases.