Skip to content

More class usages reported and labelled by what they are, property hook fixes

Latest

Choose a tag to compare

@spaze spaze released this 13 Oct 00:57
· 10 commits to main since this release
v4.15.0
3880759

New

  • More usages of classes, interfaces, enums and traits disallowed with disallowedClasses or disallowedNamespaces are reported: instanceof, first-class callables like Foo::bar(...), DNF types like (A&B)|null, types of class constants, and interfaces extended by interfaces or implemented by enums (#444)
  • Disallowed names are labelled by what they are, Class, Interface (with the new disallowed.interface identifier), Enum or Trait, also in static calls, extends and implements, which said Namespace before; only use imports keep Namespace because they can also import a namespace (#440, #443 - possible BC break)
  • Property hooks are treated like methods by the attribute-based directives: an attribute placed on a hook counts as used in the hook, and allowInClassWithMethodAttributes sees attributes on hooks; matching hooks by name like Foo::$bar::get() in allowInMethods is now documented (#441, #445)

Bugfixes

  • A disallowed enum case or constant like Suit::Hearts was reported twice, as a class and as an enum, now it's reported once as Enum (#440)
  • A disallowed item used in a property hook crashed the analysis with ReflectionException when the config had allowInMethodsWithAttributes, allowExceptInMethodsWithAttributes or their aliases (#441)
  • A disallowed item used in a named function declared inside another function or method caused "Reflection error" with the same directives, and the rest of the file wasn't analysed (#442)
  • self::, static:: and parent:: calls aren't reported as Namespace self is forbidden. anymore when a wildcard pattern happens to match them (#443)
  • str_contains() isn't used anymore, it doesn't exist on PHP 7.4 (#436)

Internal changes

  • No errors with PHPStan 2.3, which analyses for the lowest PHP version in composer.json (#439)
  • Testing on PHP 8.6 (#438)
  • PHPStan1Compatibility renamed to PHPStanCompatibility, because it covers older PHPStan 2.x versions too (#441)
  • The e2e workflow follows the moved monorepo dev tools (#437)

Possible BC break note: messages and identifiers changed for static calls, extends and implements (Namespace/disallowed.namespace is now Class, Interface, Enum or Trait), for interfaces and traits anywhere else (Class/disallowed.class is now Interface/disallowed.interface or Trait/disallowed.trait), and for enums in type declarations (Class is now Enum). The duplicate Class error for enum cases and constants is gone. If you match these errors in ignoreErrors or a baseline, they may need updating, and the newly reported usages can add errors.