Download the PHP package kenaths/phpstan-fixer without Composer
On this page you can find all versions of the php package kenaths/phpstan-fixer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpstan-fixer
PHPStan Auto-Fixer
A production-ready, comprehensive tool that automatically fixes PHPStan errors in your PHP code. Now with enhanced type safety, perfect indentation handling, and full PHP 8.4 support! 🚀
Features
✨ Core Capabilities
- ✅ Automatically fixes common PHPStan errors with 95%+ accuracy
- ✅ Production-ready safety mechanisms with comprehensive error handling
- ✅ Perfect indentation preservation - maintains your code style exactly
- ✅ Advanced type consistency fixing - resolves complex type mismatches
- ✅ Smart array type inference - detects and applies optimal array types
- ✅ Full support for PHP 8.2, 8.3, and 8.4 features
🔧 Advanced Features
- ✅ Smart Mode with multi-pass analysis and intelligent caching
- ✅ Supports all PHPStan levels (0-9) with level-appropriate fixes
- ✅ Atomic fix application with automatic rollback on errors
- ✅ Extensible architecture for custom fixers
- ✅ Modern PHP type system support (union, intersection, DNF types)
- ✅ Command-line interface with comprehensive options
- ✅ Optional backup files before making changes
- ✅ Dry-run mode to preview fixes safely
Installation
Install via Composer:
Usage
🚀 Quick Start
Fix PHPStan errors in your source directory:
🎯 Advanced Usage
Smart Mode (recommended for complex projects):
Preview fixes safely without making changes:
Use custom PHPStan configuration:
Fix specific files:
Verbose output for debugging:
Create backup files before making changes:
Increase memory limit for PHPStan:
Programmatic Usage
🆕 Recent Improvements (v2.0)
Enhanced Type Safety & Indentation
We've significantly improved the fixer with production-grade enhancements:
🎯 Perfect Indentation Handling
- Problem Solved: PHPDoc comments now maintain perfect 4-space alignment
- Technical Fix: Proper line-start position calculation for AST node insertion
- Result: Consistent, professional code formatting that matches your existing style
🔧 Advanced Type Consistency Fixing
- Problem Solved: Complex type mismatches like
?Closureproperty withstringassignment - Technical Fix: Intelligent union type creation (
string|Closure|null) - Result: Type-safe code that maintains backward compatibility
🛡️ Production-Ready Safety
- Comprehensive error handling with graceful fallbacks
- Input validation and edge case protection
- Atomic fix application with automatic rollback on errors
- Detailed logging for debugging and monitoring
🧠 Smart Array Type Inference
- Enhanced detection of array key/value types from assignments
- Context-aware analysis of method returns and parameters
- Optimal type suggestions like
array<string, int>vsarray<mixed>
Performance & Reliability
- Multi-pass analysis in Smart Mode for complex codebases
- Intelligent caching system for faster subsequent runs
- Improved error message parsing with multiple pattern matching
- Better AST traversal with position-aware fixes
Supported Fixes
Core Fixes
- Missing Array Value Types ⭐ Enhanced - Adds comprehensive array type annotations (
array<string, mixed>) - Type Consistency Errors ⭐ New - Fixes property/method type mismatches with union types
- Missing Return Types - Automatically infers and adds return types with union type support
- Missing Parameter Types - Adds type declarations to method parameters with proper PHPDoc
- Missing Property Types - Adds type declarations to class properties with perfect indentation
- Undefined Variables - Initializes undefined variables with appropriate types
- Unused Variables - Removes unused variable assignments safely
- Strict Comparisons - Converts
==to===and!=to!== - Null Coalescing - Converts
isset() ?:to??operator - PHPDoc Fixes - Fixes invalid PHPDoc tags with consistent formatting
PHP 8+ Modern Features
- Union Types - Handles
string|intand complex union types - Intersection Types - Supports
Foo&Bartype declarations - DNF Types - Disjunctive Normal Form types like
(A&B)|C - Readonly Properties - Adds readonly modifier and ensures types
- Enums - Fixes enum backing types and cases
- Constructor Property Promotion - Converts traditional properties to promoted ones
- Never Type - Properly handles
neverreturn type - Mixed Type - Smart inference of
mixedtype - Match Expressions - Type inference for match expressions
- First-class Callables - Proper handling of callable syntax
- Property Hooks - Basic support for property access patterns
Creating Custom Fixers
You can create custom fixers for specific error types:
Configuration
Create a phpstan.neon file in your project root:
Limitations
Not all PHPStan errors can be automatically fixed. Some errors require human intervention to understand the intent of the code. The library will report which errors it couldn't fix.
Common unfixable errors include:
- Complex type mismatches
- Logic errors
- Missing dependencies
- Errors requiring architectural changes
Safety
- Use
--backupto create.bakbackup files before modifying any source files - Use
--dry-runto preview changes before applying them - Always review the changes and test your code after running the fixer
- Use version control to track changes
Contributing
Contributions are welcome! To add support for new error types:
- Create a new fixer class extending
AbstractFixer - Implement the required methods
- Add tests for your fixer
- Submit a pull request
License
This library is open-source software licensed under the MIT license.
Tips
- Start with lower levels: Begin with level 0 and work your way up
- Use version control: Always commit your code before running the fixer
- Review changes: Automated fixes may not always match your intent
- Combine with CI: Run PHPStan in your CI pipeline after fixing
- Custom fixers: Create fixers for your project-specific patterns
Troubleshooting
"PHPStan executable not found"
Make sure PHPStan is installed:
"Autoloader not found"
Run composer install:
Fixes seem incorrect
- Check if you're using the correct PHPStan level
- Review the specific error message
- Consider creating a custom fixer for your use case
- Some fixes are generic and may need manual adjustment