sepmni / strict-types
Adds strict types declaration recursively to your PHP files
Requires
- php: ^7.2 || ^8.0
README
The PHP Strict Types Adder is a Composer package that allows you to automatically add declare(strict_types=1);
to PHP files within a directory recursively. It ensures your PHP files are consistent and have strict type checking enabled without the need for manual editing.
Features
- Recursively add
declare(strict_types=1);
to PHP files within a specified directory. - Ignores files that already have a
declare(strict_types=1);
statement. - Excludes files within the "vendor" folder and those with ".blade.php" in the name.
- Automatically detects and handles existing
<?php
tags.
Installation
You can install the PHP Strict Types Adder using Composer:
composer require sepmni/strict-types
Usage
Once installed, you can use the command-line interface (CLI) to add declare(strict_types=1);
to your PHP files.
php vendor/sepmni/strict-types/st.php add /path/to/your/php/files/directory
Replace /path/to/your/php/files/directory
with the path to the directory you want to process.
Example
Let's say you have a project directory structure like this:
project/
├── src/
│ ├── app.php
│ ├── other.php
└── vendor/
├── ...
To add strict types declarations to all PHP files in the src/
directory (excluding those with existing declarations), you would run:
php vendor/sepmni/strict-types/st.php add project/src
The package will process all PHP files within the specified directory and its subdirectories.
Contributing
If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and write tests.
- Submit a pull request with a clear description of your changes.
License
This package is open-source software licensed under the MIT License.
Support
If you have any questions or encounter issues, please feel free to open a GitHub issue. We welcome your feedback and contributions!
Acknowledgments
Special thanks to the PHP community and the tools that made this package possible.