Mass setting strict types to true using Laravel Pint
Laravel Pint is a handy little package that helps you fix PHP code style in a Laravel project. On top of fixing code style, you can also set some rules and simplify repetitive tasks using this package.
For instance, today I learned, if you want to set the strict_types
directive to true
in all your PHP files to enforce strict types, you can do so using Laravel Pint.
All you need is to create a pint.json
file in the root of your Laravel project and set declare_strict_types
to true
under the rules
key like so.
{
"preset": "laravel",
"rules": {
"declare_strict_types": true
}
}
Once done, you can run the pint
command and specify the path in which you want to add declare(strict_types=1);
at the top of all your PHP files.
./vendor/bin/pint app/
Here’s what it looks like in action.
And this is where it will add the declare(strict_types=1);
directive in all your PHP files.
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.