Skip to content

Releases: phpstan/phpstan

0.10.7

28 Dec 14:01
Compare
Choose a tag to compare

0.10.6

04 Dec 07:49
Compare
Choose a tag to compare

0.10.5

20 Oct 17:42
Compare
Choose a tag to compare

Fixed two PHAR-related autoloading issues that originated in 0.10.4:

  • When running phpstan executable from phpstan-shim instead of phpstan.phar, the message "Fatal error: Cannot redeclare composerRequired3df62903055312660ab99fff5d55b82()" appeared. That's because PHP construct require_once didn't recognize the same file was already loaded. Fixed by checking defined constant about PHPStan runtime: 4dfaaac
  • When running PHPStan's PHAR in a project where PHPStan is already installed locally, the message "PHP Fatal error: Uncaught TypeError: Argument 1 passed to _HumbugBox52624676281c\Symfony\Component\Console\Application::add() must be an instance of _HumbugBox52624676281c\Symfony\Component\Console\Command\Command, instance of PHPStan\Command\AnalyseCommand given" appeared. That's because the project autoloader had priority. Fixed by switching the order of autoloaders (they are prepended): c6a8cd1

0.10.4

20 Oct 13:44
Compare
Choose a tag to compare

Improvements

  • Support resolving correct types with array destructuring like list() or [] (#1436), thanks @pepakriz!
  • Support for generics syntax for iterable types like Generator or ArrayObject (73cc211) - you can now write Generator<Foo> in phpDoc.
  • Advanced trimming of current working directory and analysed path prefixes from result output (a06113c)
  • Support the never type in phpDoc (#1472), thanks @JanTvrdik!
  • Support for Closure::call() (1dc18f2), #143

Bugfixes

  • Adds properties for Directory class (#1381), thanks @josephzidell!
  • Fixed union of long strings (c4eb8ec), #1396
  • Upgraded XdebugHandler to handle --ansi (c19fef0), #1336
  • switch with instanceof should work with any truthy condition (6dff15c)
  • Fixed NullType::toArray() (b1df61a), #1371
  • Always load the closest PHPStan autoloader (0522ac2) - this prevents weird "class not found" errors for PHPStan internals, when running globally installed (or through Docker) PHPStan on a local project where vendor/autoload.php exists.
  • Add properties for DatePeriod class (#1458), thanks @cs278!
  • Adding support for second parameter of print_r (returns string when true) (#1471), thanks @jaydiablo!
  • Add dynamic return type extension for curl_init with no parameters (#1484), thanks @iluuu1994!
  • ResourceType can be cast to integer (#1481), thanks @icanhazstring!
  • Fixed always-true reports on string offset access (103dd17), #1376
  • Fixed do-while after loop condition filtering (4602eaf), #1490
  • Fixed casting non-user-defined classes to array (1d79b2c), #1446
  • Make variadic parameter optional in closure (4217103), #1390, #1407
  • Handle Closure::call only for anonymous function nodes, not all types (bbdd176), #143
  • Fixed resolving nested method calls that return $this (7345388), #1493
  • Dynamic return type extension for end() function (#1370), thanks @pepakriz!
  • Added alternative spelling of Redis::setEx and setNx (1590d4b), #1520

Function signatures fixes

0.10.3

12 Aug 16:16
Compare
Choose a tag to compare

Improvements

  • Official Mockery extension! Check it out at https://github.com/phpstan/phpstan-mockery!
  • Callables and closures can specify parameter types and return types in phpDocs! (#1353, af3c9fc, 2855ad6), thanks @JanTvrdik!
  • Experimental: Extensions can override interpretation of phpDocs (7b23c31)
    • The Mockery extension already takes advantage of this so that Foo|\Mockery\MockInterface results in an intersection type and not a union type.
  • analyse command: --error-format is encouraged instead of --errorFormat (#1338), with backwards compatibility, thanks @pierredup!
  • Dynamic return type extension for array_key_exists() (1108652)
  • Small performance gains after regressions in 0.10.2 (0d8b77c, f45589b), #1259, #1304

Bugfixes

  • array_search related fixes (#1291, #1295, #1319, #1347), thanks @CzechBoy!
  • Fixed weird error with call() on mixed (69509a3), #1273
  • Fixed issue with loops and NeverType in first iteration (ee26b13), #1312
  • TypeCombinator - fix unions of intersections (e346d3f), #1302
  • Fixed unpacked args for array functions like array_intersect_key (9e246e5)
  • property_exists() - it's never always true for universal object crate classes (76ec79f)
  • Fixed variable assignment in switch condition (d04bf35), #1350
  • Fixed accepting array of multiple callables in callable[] (43e09be), #1285

Function signatures fixes

0.10.2

22 Jul 19:41
Compare
Choose a tag to compare

Improvements

  • in_array() type-specifying extension (ba14351)
    • Specifies the type of the first argument (needle)
    • Reports if the in_array() call is always true or false
  • array_key_exists() type-specifying extension (8ac4303)
    • Notes when an array offset surely exists
    • Casts mixed second argument to array
    • Reports if the array_key_exists call is always true or false
  • Foreach - support @var annotation even for keys (7bf4836)
  • Use dynamic method return type extension registered for offsetGet when accessing offsets on ArrayAccess (41f478d)
  • Universal object crate classes look at __get return typehint to determine the property type (e705354) - especially useful for SimpleXMLElement
  • Check - calling static method on an interface (a70be05)
  • Improved analysis of functions that can't exist, like Apache, FPM, Xdebug (8b61167) - #1185

Bugfixes

  • Fixed binary + operation between array unions (44ff95c) - #1128
  • DuplicateKeysInLiteralArraysRule - fixed wrong message (a566b22) - #1144
  • Instanceof on $this inside trait can never be a constant boolean (ba3fdf1) - #1143
  • ConstantArrayType - improved callables support (df58b18) - #1150
  • Improved method_exists support (1e63087) - #1150
  • TypeSpecifier - filter by truthy/falsey values for right expressions in && and || (fcb1b41)
  • Fixed invalid offset-does-not-exist-on-array error (5727e8e) - #1062, #1063
  • Result of exponentiation operator is benevolent union of float|int (08788df)
  • Fixed looking for variables in yield (c86593a) - #1161
  • Anything::class is at least a string (4b7788c) - #1173
  • Fixed assigned variable from while loop condition in while loop body (c29225f)
  • Simplified concatenating strings to prevent combinatorial explosion (7190ec9) - #1172
  • isset() on a constant array does no longer result in a mixed offset value (594efc6, 88d6efb) - #908
  • Fixed coalesce for array dim fetches and non-null left types (28c5ff6) - #1156
  • Fixed assigning array items to properties (daea852) - #1111
  • Array constructed in foreach does not loose item type (1e4092a) - #1030
  • TypeSpecifier - recognize true/false/null in any expression, not just ConstFetch (6a551b5)
  • isset() support through an accessory HasOffsetType type (5738433, 86a7945) - fixes #908, #991, #1189
  • Improved StringType and ConstantStringType offset access (fcc23ba) - #1188
  • isset() should not complain about maybe offset accessible types (fe7fefa)
  • SimpleXMLElement can be cast to scalar (726b517)
  • SimpleXMLElement can also accept scalars (66a134b)

Function signatures fixes

Internals

  • property_exists() support reworked with an accessory type (0248d07)
  • Specifying property in isset() using HasPropertyType (974593d)
  • IntersectionType - do not include accessory types in typeOnly description (e7b016b)
  • Describe argument type verbosely if the parameter type is callable (83998c3)
  • Faster Travis tests (#1190), thanks @szepeviktor!
  • Fix ClosureType - no longer CompoundType (c6106ed)
  • Scope - make handling of ArrayDimFetch overridable (2efc46a)
  • Allow custom Scope child class (9f323f4)
  • Enhancements to CI build script by @localheinz, thanks!

0.10.1

01 Jul 18:45
Compare
Choose a tag to compare

Improvements:

  • Support for method_exists (69ef4b1) - #323
  • Dynamic constants - PHPStan lets you configure which constants can have different values in runtime using dynamicConstantNames configuration key - to avoid messages like "comparison using === between true and false will always evaluate to false" - #1083, thanks @CzechBoy!
  • Support define() and defined() in local scope - checked constants are no longer reported as undefined! (a4e248e)
  • version_compare() dynamic return type extension - #1101, thanks @lookyman!
  • Add APIs for @internal and @final attributes - #1103, thanks @iluuu1994!
  • CLI application catches exceptions by default leading to nicer error messages - #1140, thanks @lookyman!
  • Added debug filepath in case of MissingPropertyFromReflectionException or MissingMethodFromReflectionException ("different version of class is autoloaded")
  • Partially correct casts are now reported on level 6 instead of level 2 (77de7a1) - #1130

Bugfixes:

  • get_parent_class can return false (9ce4f47)
  • __CLASS__ magic constant outside of class contains empty string (1747bf9) - #1087
  • SplFixedArray::__construct argument is optional - #1089, thanks @ntzm!
  • get_headers added optional context parameter - #1097, thanks @CzechBoy!
  • Added ReflectionType::getName() (9a9b549) - #1133
  • DOMNamedNodeMap::getNamedItem can return null - #1118, thanks @iluuu1994!
  • ob_get_status does not return false (2d1c9ee)
  • Cleaned up and fixed OCI-Collection and OCI-Lob signatures (6149780) - #1123
  • Fixed variadic closures (ffd57a3)
  • Access array offsets on bool/float/int/resource (213ab3c) - #1127
  • Fixed instanceof with strings union as class (e3cf7d6) - #1126
  • Fixed calling methods/properties/constants on unions of strings (dceb632) - #1094
  • ObjectType - support Traversable, Iterator etc. directly and not just its subclasses (089439c) - #1095
  • $this with assertion didn't match $this return type (1274882) - #1112
  • set_error_handler returns a callable (b389b94) - #1116
  • printf() and sprintf() accept object with __toString() even on strict types (5297029) - #1090
  • printf() and sprintf() can also accept boolean (8e08625)
  • SoapFault constructor now detected correctly (e955f3b, 9c0f158) - #1108
  • Fixed return type of FilesystemIterator::current (b82b6a9) - #1113
  • Fixed removing array/Traversable from iterable (3cc1716) - #1139
  • static::CONSTANT gets resolved to mixed if not in a final class (bbde537) - #1138

0.10

24 Jun 18:15
Compare
Choose a tag to compare

This release has been in the works for the past 5 months - it contains advancements on several fronts at once and I can't wait till you get your hands on it! It has the most new commits (over 500) of any PHPStan release ever, see this chart for comparison.

PHPStan 0.10 has been made possible by Auxmoney.com:

Auxmoney.com: PHPStan helps us to keep code quality on a high level and focus on the business that matters most for us. Keep going!

Also, my work on PHPStan is enabled by generous patrons over at Patreon. If PHPStan makes your life easier, consider a contribution, it'll be greatly appreciated!

Besides many new features and improvements to the core (which you can read about below), there were many improvements made over at related packages. See the release notes for phpstan-strict-rules and check out brand new package for detecting usage of @deprecated elements - phpstan-deprecation-rules. Also, you should check out great 3rd party package from @pepakriz pepakriz/phpstan-exception-rules that enforces putting your exceptions into @throws phpDoc tag and checks that you actually catch thrown exceptions from called functions!

Major new features

  • Constant value types (#828), thanks @JanTvrdik!
    • Big improvement to PHPStan's type system
    • Enables recognizing not only types, but also values of expressions in cases where they're known
    • For example:
      • Format string for sprintf() can first be put into a variable and then used in a function call; the placeholders/arguments count mismatch will still be recognized
      • Specific types and values of accessed array offsets are now recognized (#409)
      • PHPStan can recognize impossible comparisons of specific values, like count($array) === 3 when there are only two items in the array
      • Results of arithmetic operations of literal values are also precisely calculated
      • And many more improvements that make the analysis of your code much smarter!
  • Typehints for built-in PHP functions (f486280, milestone link)
    • Until 0.9 (including), PHPStan relied on built-in reflection which doesn't contain any typehint data at all, and is also full of inconsistencies
    • PHPStan will finally tell you that you're passing wrong parameter types to PHP functions like date
    • It will also make use of documented return typehints
    • The analysis can now be quite brutal - some PHP functions can return false in case of some rare error - this will make your analysis fail if you're on level 6 or 7. If you're overwhelmed by the number of reported errors, lower your level to 5 temporarily and fix the reported errors later.
  • Type-specifying extensions (#825), thanks @lookyman!
    • PHPStan can now recognize types after custom method calls like assertInstanceOf, assertInt etc.
    • 1st party extensions for most common assertion libraries are available:
    • Works with already available detections of always-true and impossible type comparisons
    • Write your own type-specifying extensions for situations like has+nullable get methods or supports() calls - see #201, #534, #634
  • Improved callables support
    • New check: Is $c() a callable? - level 2 (c5e6f49) - #733
    • Detect valid and invalid callable strings, arrays and classes with __invoke
    • Check passed parameters count and types into all callables, including anonymous functions
  • New check: Nonexistent and inaccessible array offsets - level 3 (d86efca)
  • New check: Detect always truthy/falsey conditions - level 4 (689e956)
    • Detects cases like:
    • if ($object) { }
    • if (DIRECTORY_SEPARATOR === '/' || DIRECTORY_SEPARATOR === '\\')
  • New check: invalid arithmetic and binary operations - level 2 (2917336)
    • Detects $string + $string, $int . $int etc.
    • Detects non-numeric types on +$expr and -$expr
    • Detects invalid types for ++ and -- operators
    • Also detects possible division by zero
  • New check: invalid casts - level 2 (4a72885)
    • Detects (string) $stdClass or (int) $array.
  • New check: validate types inside @throws phpDoc tag - level 2 (3d6904b) - #1001, thanks @Majkl578!
  • New check: validate types in throw keyword (44b4680) - #1041, thanks @pepakriz!
  • Concept of a benevolent union type in vein of gradual typing (8ee7c6e)
    • For example array key type with mixed key will either be int or string - (int|string) (benevolent union type is marked with additional parentheses around it) will not be reported when passed to int and string even on the highest level because the code might be actually correct. But it will be reported when passed to a completely different type, like object.
  • Changes to levels:
    • Accepting types - moved partially correct union types checks from level 5 to level 6 (d514655)
    • If method/property/constant surely does not exist on a union, report that on level 2 (previously reported on level 6) (9e38fd1)
    • Reporting of accessing properties and methods on classes with magic methods (__get, __set, __call, __callStatic) moved to level 1 (455fb7b)

Improvements

  • Support for array access on objects with ArrayAccess interface (#620), thanks @pepakriz!
  • Auto-discover phpstan.neon{,.dist} config files (#509), thanks @Majkl578!
  • Allow paths and level be specified in config (#508), thanks @Majkl578!
  • array_keys, array_values, array_merge, array_fill, array_fill_keys, array_map, array_pop, array_shift dynamic return type extensions (559b9d0, 40e1782, 9e97918, a063a42, 4779c7e, 5a6f3a2)
  • TypeSpecifier: support loose comparison with null (#833), thanks @JanTvrdik!
  • Allow early terminating static calls (#822), thanks @ndench!
  • Better support for accepting objects with __toString() as strings (043081b)
  • Result of === or !== might be constant boolean (477b55d)
  • Result of instanceof might be constant boolean (00014ce)
  • Result of is_* functions might be a constant boolean type (f8c6ef0)
  • StrictComparisonOfDifferentTypesRule - check always true comparisons (off by default) (407146b) - enabled in phpstan-strict-rules
    * Improve error message for command not found (#851), thanks @fain182!
  • sorting of file-specific Error entries by file name and line number (#838, #841) - thanks @Ocramius!
  • Implemented JSON formatter (#783), thanks @soullivaneuh!
  • self, static and parent - consistent case-insensitive handling (27f084e)
  • Use Composer/XdebugHandler to avoid performance penalty from Xdebug (#874), thanks @AJenbo!
  • TypeSpecifier - support instanceof parent (af17140)
  • reset() dynamic return type extension (3485d8c)
  • Detect exception class name with wrong case in catch block (597bbed)
  • Checking wrong function name case moved to strict-rules (4de98a1)
  • Improved type detection in (object) cast (6231eb1)
  • Fixed phpDocs interpretation when analyzing traits (9aaddbc) (#174)
  • Added support for is_scalar type-specifying function (4abeceb)
  • Fixed resolving UnaryMinus type (c845439)
  • Checking for invalid part of encapsed string ("Foo $objectWithoutToString bar") - level 2 (5010703)
  • InstantiationRule - warn about incorrect case name when the class has no constructor (9a21518)
  • Improved float, int and bool cast evaluation (6e2fc06)
  • min() and max() dynamic return type extensions (58fe09f)
  • is_subclass_of type-specifying extension (4e1b2d8) - #889
  • Type-losing, although consistent behaviour of parameters passed by reference (711413f)
  • pathinfo() dynamic return type extension (4d8c625)
  • Constant values for magic constants (b492ea8)
  • Report and check return types of magic methods (71e120a)
  • No need to update scope for the last node in sequence (8c3880f)
  • Array with mixed key type have int|string iterable key type (0acbd53) - #956
  • Improved support for anonymous classes (de7fd7d, f416740...
Read more

0.9.2

28 Jan 14:23
Compare
Choose a tag to compare

Bugfixes:

  • Support object typehint in closures (67aaf24) - #664
  • Support parent typehint in closures (78b4b8e) - #664
  • Fixed issue with universal object crate classes (99f4195) - #663
  • VariableCertaintyInIssetRule - do not check never-defined variables in global scope (03d73a9) - #674
  • Fixed case when the autoloader encounters class_exists or similar call (962e5dd) - #754, thanks @Slamdunk!
  • get_defined_functions function has one optional parameter (de167d1) - #756, thanks @carusogabriel!
  • Fixed callable instanceof (5879f70) - #760
  • InvalidPhpDocTagValueRule - do not report tags mentioned in the middle of a description (8dddd06)
  • Fixed switch issue with multiple early-terminating statements in a case (870e449) - #693
  • Fixed evaluation of short ternary operator (14f1e1c) - #749
  • More ternary operator fixes (bfdd4ac)
  • For loop - condition must be evaluated after loop statements have possibly ran (0af3f4c) - #698
  • While loop condition can be influenced by the loop body (df13d5f) - #743
  • CallToNonExistentFunctionRule - fixed handling timecop extension functions (8fe942a) - #769
  • VariableCertaintyInIssetRule - do not report always existing variables in finally block (1aed7a5
    ) - #766
  • finally block cannot rely on the whole try block being executed - influences variable types and definition certainty (7efd23c) - #778
  • Fixed issue with foreach variable (236bb9b) - #622
  • Fixed issue with empty catch block (9de0492) - #642
  • Support for logical and & or operators (2ccadb6) - #774
  • Variable is set when isset() asks about property or array index on a variable (062f455) - #744
  • Fixed foreach issue with variable certainty after the loop (0da95fc) - #778
  • Ignore nonexistent getallheaders function (61091bb) - #781
  • TypeSpecifier: fix is_a with static::class (e21b4de) - #788, #792, thanks @JanTvrdik!
  • Detect unknown classes in array and iterable key types (eb9d1cd) - #790
  • isset() also ensures non-nullability of all chain elements (6a0adc2) - #799
  • Fixed variable certainty in for loop condition (b7e7158)

0.9.1

02 Dec 19:59
Compare
Choose a tag to compare
  • Support for PHPUnit 6.5 which renames MockObject (5adffb5)
  • Fixed calling static methods of object|string union, accessing static properties and constants as well (44d6482, 801237d, c57244d) - #637
  • Switch - fallthrough conditions should not be taken into account when they could be skipped (d1c2ff9) - #629
  • Fixed analysis of anonymous classes with comments above them (5014c0e) - #632, thanks @cs278!
  • ArrayType: mixed array is maybe callable (c42e30b) - #638, #639, thanks @JanTvrdik!
  • Do not attempt to repair invalid type in PHPDoc because it leads to unexpected results (fa71b51) - #654, thanks @JanTvrdik!
  • Inline T[] only when subtype of existing iterable value type (2a7c92d) - #636, #650, thanks @JanTvrdik!
  • Index dynamic method extensions lazily outside of Broker constructor to avoid circular dependency (ef60e5c)
  • Fix version shown in the PHAR (f32841e) - #649, thanks @Jean85!
  • Fixed openssl_x509_parse - second parameter is optional (056e24c) - #643