By kingdutch on
Change record status:
Draft (View all draft change records)
Project:
Introduced in branch:
Introduced in version:
Issue links:
Description:
Type annotations in PHPDoc comments should no longer use the Fully Qualified Class Name (FQCN) and instead include only the class name relying on a use-statement if the referenced class is not in the same namespace as the file in which it's referenced.
Use statements should be added even if the type is only referenced by a PHPDoc. This method of reference is supported by tools such as PHPStan and major IDEs and follows the convention of other frameworks.
Note that the examples below show only @param but apply equally to @return, @var, etc.
Before
declare(strict_types=1);
namespace Drupal\example\Service;
use Drupal\Core\Render\Renderer;
class ExampleService {
/**
* @param \Drupal\Core\Render\Renderer $renderer
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $phpDocTypedOnly
* @param \Drupal\example\Service\Otherservice $other
*/
public function __construct(
protected Renderer $renderer,
protected $phpDocTypedOnly,
protected Otherservice $other,
) {}
}
After
declare(strict_types=1);
namespace Drupal\example\Service;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\Renderer;
class ExampleService {
/**
* @param Renderer $renderer
* @param EntityTypeManagerInterface $phpDocTypedOnly
* @param Otherservice $other
*/
public function __construct(
protected Renderer $renderer,
protected $phpDocTypedOnly,
protected Otherservice $other,
) {}
}
Impacts:
Module developers
Themers
Site templates, recipes and distribution developers