coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

New sniff to ensure constants being typed using native types

Open DaDeather opened this issue 1 year ago • 0 comments

Currently there's no sniff to ensure that constants are typed through native types.

I'd like to introduce a sniff that enables this and ensures the following:

class A
{

	const null AA = null;
	const true AAA = true;
	const false AAAA = false;
	const string AAAAA = 'aa';
	const int AAAAAA = 123;
	const float AAAAAAA = 123.456;
	const array AAAAAAAA = ['php'];
	const int AAAAAAAAA = -123;
	const float AAAAAAAAAA = -123.456;

}

This is available since PHP 8.3. See: https://wiki.php.net/rfc/typed_class_constants

DaDeather avatar Oct 14 '24 08:10 DaDeather