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.
👋 Hi there! This is Amit, again. I write articles about all things web development. If you enjoy my work (the articles, the open-source projects, my general demeanour... anything really), consider leaving a tip & supporting the site. Your support is incredibly appreciated!

