The June 2022 relese of PHP Tools, the version 1.66
, has been released. It brings the great Code Lens adornments into the PHP editor, the support for Eloquent local scopes to the PHP IntelliSense, improved inferring of generic types using class-string<T>
annotation, and more!
The release 1.66
introduces Code Lenses for PHP code. This neat feature, best known from C# in Visual Studio and from Visual Studio Code, helps with navigating through definitions and references.
Code Lenses are displayed above each function, class, interface, trait, enum, and properties. This little adornment is seamlessly showing number of references and implementations. For overriden methods, it's also providing a quick link to the parent definition (displayed as prototype
).
The image above displays code lenses for a PHP class and PHP methods.
The feature can be enabled or disabled in
Tools
/Options
, underText Editor
/All Languages
/CodeLens
, the optionEnable CodeLens
. It is available in Visual Studio 2019, Visual Studio 2022, and further.
class-string<T>
There is a special syntax used in Documentary Comments to annotate a variable, which value should be a name of a class. It's usually used by code linters like PHPStan or Psalm.
PHPTools now use this annotation in combination with the support for generics. Parameters annotated with class-string<T>
, where T
is a template arguments, allows the editor to infer the type of T
when possible.
Consider the following code:
/**
* @template T of Foo
* @param class-string<T> $class
* @return T
*/
function instantiator(string $class) { ... }
Now, whenever the editor know the value of $class
, it can infer the type T
, and thus recognize the type of instantiator
return value. This helps user with IntelliSense, code completion, and further code analysis.
The screenshot above shows the use instantiator()
function.
The editor recognizes real-time facades, and provides code analysis, code completion, and overall IntelliSense for them. Each class name which is prefixed with Facades\
is treated as a real-time facade (in case there are Laravel Facades included in the project).
With the support of real-time facades, user is getting code completion as on the picture below, including all the code checks.
We have added an initial support for Eloquent's Local Scopes, i.e. functions prefixed with scope
in the Eloquent Model. Those functions show up in the IntelliSense without the prefix as both static and non-static with its scoped arguments.
The editor scans for the local scopes (the functions prefixed with scope
on a class that implements Illuminate\Database\Eloquent\Model
or on a trait that is used within a Model
class); such functions are displayed in the IntelliSense and also recognized by the code analysis.
The feature is in-progress. We're still working on it. Although we hope even this will help with coding.
PHP notices and warnings sometimes slide unnoticed. They are now displayed in the Debug Output Pane.
->
supported, and not reported as syntax error anymore.->
with new
in the expression chain.use
when it is actually used in an Doc Comment which is not associated with anything.@test
Doc Comment.F12
) on PHP manual symbols.