Releases: phpstan/phpstan
0.6.1
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
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()
andempty()
on static properties access throughstatic::
- Support for properties
isset()
andempty()
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
andarray_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 afterfopen()
orfile_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
0.5.1
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
|
(likeFoo|Bar
with the exception ofnull
) 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 enteringforeach
. - 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.
- Union types support. On level 0-4, any type connected with a
true
orfalse
(as opposed tobool
) 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/orfunc_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 likestatic[]
- 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
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:
0.4.1
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
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
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
toanalyse
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 parametercustomRulesetUsed
inparameters
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 toanalyse
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) toanalyse
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