Skip to content

PHP 8 and new documentation

Compare
Choose a tag to compare
@i582 i582 released this 18 Aug 07:07
· 97 commits to master since this release
2f67947

A lot of time has passed since the v0.2.0 (v0.3.0 was minor) release, so the list of changes is very long.

The goal of this release is to start a new development phase with scheduled releases and respecting backward compatibility.

Big features

  • PHP 8 and PHP 8.1
  • 40+ new checkers
  • New CLI
  • New documentation

Checkers

New checkers

  • paramClobber
  • printf
  • offBy1
  • argsOrder
  • callSimplify
  • discardVar
  • strictCmp
  • dupCatch
  • catchOrder
  • indexingSyntax
  • trailingComma
  • emptyStmt
  • stripTags
  • nestedTernary
  • intNeedle
  • angDeprecated
  • emptyStringCheck
  • oldStyleConstructor
  • returnAssign
  • strangeCast
  • classMembersOrder
  • badTraitUse
  • varShadow
  • invalidNew
  • countUse
  • unaryRepeat
  • forLoop
  • alwaysNull
  • selfAssign
  • errorSilence
  • switchDefault
  • switchSimplify
  • switchEmpty
  • implicitModifier
  • invalidExtendClass
  • methodSignatureMismatch
  • argsReverse
  • constCase
  • reverseAssign
  • concatenationPrecedence

Improved checkers

  • Improved dupBranchBody checker, added handling switch cases
  • Improved message for dupCond checkers for switch cases
  • Improved strangeCast checker

New checks in existing checkers

  • Added check for nullable syntax
  • Added precedence rules for ??
  • Added check for incorrect case of class names in type hints
  • Added a check for casting to the real type and using the is_real function
  • Added a check for calling array_key_exists with an object
  • Added check for calls to the random_int function
  • Added cases to callSimplify and ternarySimplify checkers
  • Added finally return check for unreachable checker
  • Added a check for array type hint
  • Added check for parent typehint in typeHint checker
  • Added check for repeated nullable
  • Added a check for using void type in the type union or @param annotation
  • Added check for class name case in const fetch
  • Added a check that the return type is defined for the callable(...) annotation

Linter

Added

  • Added type inferring for callback param type of array_map-like funcs
  • Added multi-pattern rules support via "any" blocks
  • Added handling of assignment operators (+=, -=, *=, .=)
  • Added .= <<= >>=` assignments type inference
  • Added type inference for magic constants
  • Added name case checking for self, static and parent
  • Added type inference for the null coalesce operator
  • Added support for magic constants in constant folding
  • Added arrow functions processing in linter
  • Added support for @mixin annotation
  • Added support for use [function] namespace\{A, B} syntax
  • Added check for deprecated for static methods
  • Added the ability to define a checker both in the code and in dynamic rules
  • Added detection of suspicious PHPDoc comments
  • Added support for @noinspection PhpUnreachableStatementInspection
  • Added behavior when vendor folder is added to indexing list by default
  • Added display of the number of non-critical errors
  • Added check that null is assigned to not nullable property
  • Added type inference for callable from PHPDoc
  • Added handling of unknown types-with-dashes annotations in PHPDoc
  • For iterable<T> now will be assume type array<T>
  • Added handling of the case when a static method was called through a variable
  • Added support for mixing key and non-key types in array{}
  • Added initial support of complex instanceof for if/else and ternary operator
  • Added support when no variable is specified for @var
  • Added --strict-mixed flag

Changed

  • Assume int|string array key types in foreach stmt
  • Treat trigger_error($msg, E_USER_ERROR) as exit()
  • Renamed nameCase to nameMismatch
  • --rules flag can now accept folders, in which case all files from it will be added to the rules
  • For embedded dynamic rules, all messages are capitalized
  • For messages with variables, added $ before the variable name
  • For messages related to an unused variable added mention of the --unused-var-regex flag
  • Custom types are now taken into account when getting closures

Fixed

  • Fixed --allow-checks filtering of rules
  • Fixed bug where assign null coalesce gave discardExpr warning
  • Fixed type inference for callback arguments if they have type hint
  • Fixed a panic in git mode for binary files
  • Fixed incorrect type inference for a tuple containing static, self or $this
  • Fixed false positive of parentConstructor
  • Fixed processing of variables in try-catch
  • Fixed a bug with a tuple containing an array
  • Fixed collisions for the late static binding
  • Fixed panic when used parent typehint in class without parents
  • Fixed suggest of --fix flag when the flag is already provided
  • Fixed panic if file cannot be parsed
  • Fixed a bug with @see CONSTANT_NAME
  • Fixed error when calling the define function with a slash at the beginning
  • Fixed bug in array quick fix
  • Fixed bug with quick fix, now if the check is not enabled, quickfixes will not be applied for it
  • Fixed bug with quick fix for autogenerated files, now for autogen files, quick fixes will not be applied if the flag --check-auto-generated is not provided
  • Fixed bug, when typecast to an array does overwrite existing types
  • Fixed autofix for langDeprecated.define rule
  • Fixed PHPDoc for class with modifiers
  • Fixed a bug, if the function starts with a backslash, then the type was incorrectly inferred based on meta information from phpstorm-stubs
  • Fixed arrow function handling in custom walkers

Improved

  • Improved assignOp tests
  • Improved list(...) = $a type inference for arrays
  • Improved checking for duplicate cases
  • Improved type inference for multidimensional arrays when adding elements to them
  • Improved closure and shape handling
  • Improved context line in PHPDoc warnings
  • Improved message for argCount checker

Removed

  • Removed the deprecated way to run NoVerify, now, when run without commands, help will be displayed
  • Removed langserver

Documentation

  • Added a page with all checks
  • Added Getting started document
  • Added Configuration document
  • Updated Install document
  • Updated README
  • Added documentation for baseline mode
  • Added missing information to dynamic rules documentation

Improves in CLI

  • Added the version command to replace the --version flag for the check command
  • Added a new field for version, now the version command will also show the NoVerify version number
  • Build time will now be shown with delimiters
  • Added groups for flags
  • Improved checkers command
  • Fixed output if the flag is not found

Build from source

  • Added build command to Makefile
  • Splited the check command into test and lint commands
  • Renamed build-release command with release

KPHP

  • Interpret any type as mixed
  • Added itype inferring for instance_deserialize
  • Added type inferring for instance_cast
  • Replaced array_first_element with array_first_value
  • Added type inferring for array_filter_by_key and instance_cache_fetch
  • Added type inferring for not_null, not_false and create_vector