I’ve managed to enforce strict types, but now I need to declare them in every file.
phpcbf says it has 0 fixable issues upon running.
Is there a way to automatically add declare(strict_types = 1);
to the top of every file?
ruleset.xml:
<?xml version="1.0"?>
<ruleset name="PrimaryStandard">
<description>Primary coding standard</description>
<rule ref="PSR2"/>
<rule ref="PSR12"/>
<rule ref="Generic.PHP.RequireStrictTypes"/>
</ruleset>
2
Answers
Yes, there is:
You will of course need to figure out what the files are and implement
addYourMacro
, where you textually embed it at the right place.The native
Generic.PHP.RequireStrictTypes
sniff does not have the ability to add this declaration automatically via phpcbf. For the files found, you can edit them pretty easily in the shell via sed: