I'd like to configure my phpcs ruleset so it would force the PHP 7.4 added type declaration for class properties. Currently I'm using the PSR-12 standard ruleset and I want to add there a sniff, which will scan this code:
/** @var string $timeFormat*/
protected $timeFormat = 'H:i';
protected $dateFormat = 'Y-m-d';
and show something like "Missing type declaration", so the correct code should be:
/** @var string $timeFormat*/
protected string $timeFormat = 'H:i';
protected string $dateFormat = 'Y-m-d';
Note that I'd like the sniff to warn me even in case of typehint being placed in the PHPDoc. It should demand the type declared before the property name. Is there a rule already existing for this? Thanks!
Try gskema/phpcs-type-sniff: