We're happy to introduce updates to our PHP extension for Visual Studio! Version 1.72 introduces Inlay Hints, new Code Actions, improved code analysis, improved support for Doc Comments with extended syntax for Psalm and PHPStan type names and keywords, and more!
Sometimes it is not clear what function arguments are used for. We are adding so-called inlay hints that annotate function parameters, inferred function return type, by-ref semantics to arguments, and expressions type.
Enable or disable Inlay Hints in Tools
/Options
, under Text Editor
/PHP
/Inlay Hints
,
Several quick refactorings through code actions have been added.
Assignments can be simplified with ??=
, +=
, *=
, etc.
Transforming expressions to the new nullable object operator ?->
.
Assignment using if
conditions can be simplified.
And hard-to-read switch
blocks can be simplified with the new match
expression.
enum
and BackedEnum
and UnitEnum
implicit interfacesreadonly
and enum
parsed properly when used a part of the qualified nameRandom
extensionThe PHP 8.1 enum
objects implicitly implement UnitEnum
and BackedEnum
interfaces. The BackedEnum<TValue>
interface is annotated with a template type argument so it can be used in Doc Comments with the backed type for better type analysis. E.g.:
/** @param \BackedEnum<string> $e */
function foo($e) {
return $e->value // -> string
}
enum MyEnum : string {
case A;
}
foo( MyEnum::A );
PHP Documentary Comments have been improved as well. In addition to more code diagnostics, the editor understands a wide range of Psalm and PHPStan type annotations. We've been working on recognizing commonly used type syntaxes in Doc Blocks; now supporting most of PHPStan, and other popular linting frameworks.
Image: Diagnostic showing missing variable name!
Types, including complex array shapes, generic types, template type annotations, unions, intersections, and callables; are all not properly colorized, occurrences highlighted, and code completion works (even inside <
and >
when specifying generic type arguments). Refactoring recognizes nested types within Doc Blocks, and the overall functionality of types within Doc Blocks is complete now.
Additionally, the triple dot syntax ...
is now allowed within the @param
tag, and the @param-out
tag is recognized.
@template
, @implements-*
, @extends-*
, and other notations.Traversable
types have been annotated with generic template type-arguments.foreach
works well with generic collections, Traversable
types with generic annotations.callable
, list
, and MoreSince this release, the editor supports all the syntaxes for array shapes and callables. In addition, the type analysis handles specified PHPStan types accordingly.
PHPStan and Psalm array shapes specified in PHP Doc Comments are allowed, parsed, colorized, and used in code completion and type analysis.
Additionally, list
and non-empty-list
types are handled as well. Including their generic counterparts with <
and >
types specified.
All the callable syntaxes in PHP Doc Comments are supported now as well.
array{ key: type, }
This update brings the standard types annotated with generic template types; this is especially helpful in Laravel and Symfony frameworks, where it provides type inferring for all the collections, iterables, Generator
, DOMNodeList
, etc.
This improves value inferred within foreach
for all kinds of iterables.
Checks for use of readonly
properties.
Assignment to non-existing properties is checked.
Check for use of an unknown attribute class.
Check that class used within the throw
expression is throwable.
Fixes many false-positive warnings!
Newly, we report interface
containing properties, which is not allowed in PHP.
Type analysis handles array type inferring, avoiding lots of falsy warnings.
Newly, we report invalid types in echo
and concatenation expressions.
Type analysis for array_map()
is more precise, if the "map" functions can be determined.
It is now possible to use PHPDoc right above the constructor property promotion, with just @var
annotation.
Improved analysis of define()
with object
.
match
arms.?->
./* ... */
) instead of line comment (//
)..phar
with only the main stub, no file entries) are supported./**
) respect Generator
functions.integer
, boolean
, list
types are handled properly in Doc Block.use
analysis is fixed, so it handles type names specified in Doc Blocks.session_set_cookie_params()
works for both possible definitions.Imagick
constants added.