sepehr-mohseni / strict-types
A powerful CLI tool to manage strict_types declarations in PHP files with framework presets, dry-run mode, and comprehensive testing
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sepehr-mohseni/strict-types
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5 || ^10.0
README
A CLI tool for managing declare(strict_types=1); in PHP projects.
Requirements
- PHP 7.4+
Installation
composer require --dev sepehr-mohseni/strict-types
Usage
# Add strict_types to files ./vendor/bin/strict-types add src/ # Check coverage ./vendor/bin/strict-types check . # Remove strict_types ./vendor/bin/strict-types remove src/ # Generate config file ./vendor/bin/strict-types init
Commands
| Command | Description |
|---|---|
add |
Add declare(strict_types=1); to PHP files |
remove |
Remove the declaration from files |
check |
Report strict_types coverage |
init |
Create .strict-types.json config |
help |
Show help |
version |
Show version |
Options
--dry-run Preview changes --backup Create .bak files before modifying --no-recursive Skip subdirectories --preset=<name> Use framework preset --exclude=<pattern> Exclude files matching pattern --json Output JSON (check command) -v, --verbose Verbose output -q, --quiet Suppress output
Framework Presets
Auto-detected or manually specified:
laravel- excludes blade templates, storage, cachesymfony- excludes var, publicwordpress- excludes wp-admin, wp-includesdrupal- excludes coreyii- excludes runtime, web/assetscodeigniter- excludes system, writable
Configuration
Create .strict-types.json:
{
"exclude_patterns": ["*.blade.php"],
"exclude_directories": ["vendor", "node_modules"],
"dry_run": false,
"backup": true,
"recursive": true
}
Examples
# Laravel project with backup ./vendor/bin/strict-types add --preset=laravel --backup . # Check and output JSON for CI ./vendor/bin/strict-types check --json src/ > report.json # Dry run to preview ./vendor/bin/strict-types add --dry-run app/
CI Integration
# GitHub Actions - name: Check strict_types run: ./vendor/bin/strict-types check --json . > coverage.json
Testing
composer test
License
MIT
Author
Sepehr Mohseni - GitHub