Skip to content

Releases: phpstan/phpstan

0.6.1

21 Jan 21:05
Compare
Choose a tag to compare

Bugfixes:

  • RequireParentConstructCallRule - fixed checking static method call on an expression, not class name (#92)
  • Added fourth parameter to DatePeriod constructor definition (#89)
  • Fixed a bunch of issues that emerged while using multiple class reflection extensions:
    • DefaultValueTypesAssignedToPropertiesRule - always access native class properties
    • TypesAssignedToPropertiesRule - respect local scope when getting the property
    • ClassReflection - better scope-aware caching of properties
    • ClassReflection - getting a method is also scope-aware
  • Define variables from var for further arguments in method call
  • Support assigning variables in array keys
  • Find variable assigns in left part of instanceof
  • Condition in switch statement was not processed and checked
  • Exclude analysis of traits in files excluded from analysis
  • Exclude analysis of traits outside of analysed paths
  • Method parameter with type string accepts object with __toString() method (#94)

0.6

15 Jan 20:29
Compare
Choose a tag to compare
0.6

PHPStan is on Patreon! You can show your support by backing PHPStan on Patreon. Choose your reward from different tiers and be a part of PHPStan's sustainable future development. I will deeply appreciate it. Thanks!

Major new features:

  • Support for {@inheritDoc} above methods and properties
  • Check correct $this usage (level 0) - using $this outside a class and in static context

Enhancements:

  • Union iterable type (like Foo[]|Collection) is created on all rule levels. This helps for specifying iterated value in foreach.
  • Support for isset() and empty() on static properties access through static::
  • Support for properties isset() and empty() in ternary operator
  • Checking if there's a parent typehint without parent class
  • Foo::class is of type string, not mixed
  • Support for standalone null in phpDocs
  • Specifying types returned from array_fill and array_fill_keys
  • Support for $foo instanceof static
  • Types of variables defined before for/foreach/while loop scope are now combined with types assigned to those variables inside the loop. This prevents the need for annotating such variables with /** @var */ when defining them.
  • Support negated instanceof in boolean condition (#81)

BC breaks for extension developers:

  • Added MethodReflection::getPrototype() (because of #66)

Bugfixes:

  • Fixed calling sibling method with prototype in common parent class (#66)
  • Fixed checking protected and private class members from an anonymous class
  • Fixed referencing parent in typehints
  • Fixes related to format parsing in printf and similar functions (#75, #85)
  • Fixed excluding for relative paths (#73)
  • Instance method can be called statically from an instance method when in the same class or a child (a9649ed)
  • Fixed is_null causing the expression to be null in other part of a binary operation in if and while loop condition (#81)
  • Create $http_response_header in local scope after fopen() or file_get_contents() call
  • Universal object crates extension - do not crash on nonexistent class, skip it
  • Properties missing in native PHP Reflection (like those on DateInterval or DOMDocument) are now recognized in child classes (#80)

0.5.2

08 Jan 16:20
Compare
Choose a tag to compare

Enhancements

  • Dynamic return type extensions for static method calls (#71)
  • Parse error reports a line
  • Do not report unmatched ignored error messages when analyzing individual files
  • Combining integer with float results in float instead of mixed (#60)

Bugfixes:

  • Support regex-like character classes for sscanf (#64)
  • Fixes for compatibility with Windows (#63)
  • Fixed support for trait method aliases (#69)
  • Fixed PDO::query() parameters

0.5.1

02 Jan 19:39
Compare
Choose a tag to compare
  • New check: Unused variable uses in closures (level 0)
  • Bugfix: Unused constructor parameters check did not see closure uses
  • Bugfix: Unused constructor parameters check descended into closures
  • Bugfix: Infinite traits recursion with class and trait in the same file (#61)

0.5

01 Jan 23:06
Compare
Choose a tag to compare
0.5

This is the biggest release of PHPStan yet! I and other contributors have worked hard over the holiday season to bring you awesome new features and other enhancements.

PHPStan is now on Patreon! You can show your support by backing PHPStan on Patreon. Choose your reward from different tiers and be a part of PHPStan's sustainable future development. I will deeply appreciate it. Thanks!

Major new features in 0.5

  • Completely reworked traits support. Previously, each trait was analysed separately and users complained about a lot of "method undefined" errors when calling $this->x(). In 0.5, each trait is analysed in context of class that uses it, so it's analysed multiple times for each using class. (#19)
  • Check for unused constructor parameters (level 0). If it finds one, it can either mean that it's supposed to be unused and you can safely delete it, or that you forgot to use it, e. g. assign it to a property.
  • PHPStan now reads phpDocs from functions, enriching data about parameter types and return types.
  • Check return types of functions (level 3), in a similar fashion to already checked return types from methods and closures.
  • Support for @property and @property-read annotations on classes.
  • Added experimental level 5 with two new features:
    • Union types support. On level 0-4, any type connected with a | (like Foo|Bar with the exception of null) is mixed and no checks are performed on them. On level 5, Foo|Bar is a full-fledged type checked when returning from a function or assigned to a property or an array. Additionally, if one of the types is an iterable (Foo[]|Bar), it's specifying the type of the value when entering foreach.
    • Checking arguments passed to functions and methods. This was the missing piece of a puzzle from previous versions and it brings PHPStan to a whole new level. You should have much less TypeErrors in your application thanks to it. It also works with union types mentioned above. This check even found some errors in PHPStan itself!
    • Level 5 is marked as experimental because it's a complex area and there can be some rough edges. I'd appreciate if you tried it out in your app and reported issues it finds you don't consider errors in your code.
  • true or false (as opposed to bool) are also valid types that can be documented in phpDoc
  • Check that function or method return result of type void is not further used (for methods called on $this on level 0 and for others on level 2)
  • Check whether clone is called on an object (level 3)
  • Support for empty() - it's like !isset() - variables in if (!empty(...)) are not reported as undefined, similarly with properties
  • Support for @return $this - similar resolving type logic to @return static.
  • Added --no-progress option to hide progress bar during analysis (#45)

Enhancements

  • PHPStan can be installed alongside PHP-Parser 2.x so that folks using Laravel can also analyse their code :) However, using PHP-Parser 3.x if you're on PHP 7.1 is strongly recommended and PHPStan will output a warning if that's not the case.
  • Removed tracy/tracy as a dependency. PHPStan is now more lighweight.
  • Callables accept strings (references to functions) and arrays with two strings (static methods).
  • Reporting accessing a property on an unknown class
  • Reporting calling a method on an unknown class
  • Better support for aliased classes
  • Helpful message if PHPStan crashes on low memory limit
  • Methods with func_num_args() and/or func_get_arg() are also considered variadic
  • Added %currentWorkingDirectory% config parameter
  • Variables in unset() are not reported as undefined
  • Getting type from the ternary operator, including the Elvis ?: variant
  • Getting type from coalesce ?? operator
  • Correctly resolving static type logic in more complex types like static[]
  • Getting type from clone keyword
  • Specifying expression type with is_string
  • Improved isset() support for specifying properties existence
  • Specifying expression type in switch using switch (get_class($foo)) case Foo::class:

BC breaks for extension developers

  • Added ParameterReflection::isVariadic()

Bugfixes

  • Arguments passed by reference can also define a new variable in a static method call
  • Closures recognize variadic arguments
  • Fixed "undefined variable" errors in a lot of weird code situations
  • Fixed assigning $$variable (PHPStan used to crash on internal error here)
  • Fixed error with variadic function detection
  • Protected methods from a child class can be called from the parent class.
  • Some types' description were missing |null in case of nullables.
  • Fixed strtok() call check
  • Fixes around defined variables and finally block
  • Fixed mixing variable types in some switch cases
  • float can be combined with integer resulting in float instead of mixed
  • Class reflection extension for deficiencies reported in native PHP reflection - currently supports ZipArchive properties that are missing in reflection (PHP bug #73803)

0.4.2

12 Dec 20:41
Compare
Choose a tag to compare

Enhancements:

  • PrintfParametersRule also checks calls to sscanf and fscanf
  • Better message for misconfigured autoloader when an analyzed function is not found
  • CallableType also accepts strings (references to functions) and arrays with two strings (static methods)

Bugfixes:

  • Assign new variables from variadic parameters passed by reference (#26)
  • Assigning new variables in various weird situations (#27)
  • Do not print the note about default rule level being used when a custom ruleset is present

0.4.1

06 Dec 12:00
Compare
Choose a tag to compare

Enhancements:

  • When there are no errors in an analysis with the default rule level, print a note about the default level being used and the option to perform more thorough checks with a higher rule level. (But the user can safely ignore this message and continue using the default level, he just should be aware that he's not using PHPStan to its full potential.)
  • Print a more friendly message when a class is not found due to a misconfigured autoloading.

Bugfixes:

  • iterable accepts any object that implements the \Traversable interface
  • Fixed resolving and checking nullable return types in anonymous functions
  • Fixed short array destructuring syntax in foreach

0.4

04 Dec 21:36
Compare
Choose a tag to compare
0.4

Full PHP 7.1 support!

  • Support for iterable type
  • Support for the void return typehint
  • Support for nullable parameter and return typehints
  • Support for short array destructuring syntax (shorthand for list())
  • Support for class constant visibiility

Bug fixes:

  • Constants can be accessed using parent::FOO
  • Protected static methods can be called from the parent class
  • Correct handling of nested list(...)

0.3.1

03 Dec 11:54
Compare
Choose a tag to compare
  • Allow default value null even in not-nullable properties because it's equivalent to having no default value at all (fixes #17)
  • Casting a division to float is not always useless (fixes #16)

0.3

27 Nov 19:17
Compare
Choose a tag to compare
0.3

Major new features:

  • Rule levels. If you want to use PHPStan but your codebase isn't up to speed with strong typing and PHPStan's strict checks, you can choose from currently 5 levels (0 is the loosest and 4 is the strictest) by passing --level to analyse command. Default level is 0.
  • Custom rulesets. This builds on the idea of rule levels by enabling you to create your own rulesets without limiting yourself to predefined levels. Create your own ruleset by selecting which rules you want to check by copying the service definitions from the built-in config level files in conf directory to your PHPStan project config file. Don't forget to set the parameter customRulesetUsed in parameters section of your project config file.
  • Finding useless casts like (string) 'foo'.
  • Checking the types of operands of strict comparison operators - e. g. 'foo' === 5 will always evaluate to false.

BC breaks:

  • When using a custom project config file, you have to pass the --level option to analyse command (default value does not apply here - I need some way to identify whether a custom ruleset is used or not).
  • For strictest checks, you now have to pass --level 4 (currently highest level) to analyse command.

Enhancements:

  • Removed dependency on gettext
  • Support for Closure::call()
  • Specifying return types of several array functions which depend on argument types
  • CallableType accepts obects of type Closure
  • CallableType accepts an array that is possible a callable
  • Specifying types of expressions using is_* functions
  • Specifying types using expressions in assert()
  • Division and other binary operations with floats result in mixed if either operand is mixed

Bugfixes:

  • Futher reinforce resolving type names from phpDocs
  • Closure return type is nullable when the typehint is not present