Download the PHP package lukaszzychal/phpstan-fixer without Composer

On this page you can find all versions of the php package lukaszzychal/phpstan-fixer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpstan-fixer

PHPStan Auto-Fix

CI License: MIT

Framework-agnostic PHP library for automatically fixing PHPStan errors using static analysis rules. Works with Laravel, Symfony, CodeIgniter, and native PHP projects.

Features

Installation

Usage

Basic Usage (Default - Suggest Mode)

By default, the tool runs in suggest mode - it shows what would be changed without modifying files:

This is equivalent to:

Suggest Mode (Preview Changes)

Preview proposed fixes without modifying files (same as default):

Note: Suggest mode is safe to run - it only shows what would be changed and does NOT modify your files.

Apply Mode (Write Changes)

Apply fixes directly to files:

Warning: Apply mode will modify your source files. Always review changes in suggest mode first!

Using Existing PHPStan JSON Output

If you already have a PHPStan JSON output file:

Custom PHPStan Command

Specify a custom PHPStan command:

Configuration File

You can configure how different error types are handled using a configuration file. Create phpstan-fixer.yaml or phpstan-fixer.json in your project root:

YAML Format (phpstan-fixer.yaml):

JSON Format (phpstan-fixer.json):

Configuration Actions:

Validation: configuration is validated on load. Invalid actions (anything other than fix, ignore, report) or malformed rule entries will stop execution with a clear error message.

Using Configuration:

Pattern Matching:

YAML Support:

For YAML configuration files, you need either:

Supported Fix Strategies

📖 Detailed Guide: See PHPStan Fixers Guide for comprehensive documentation on each fixer, including problem descriptions, examples, and usage scenarios.

The library automatically fixes the following types of PHPStan errors:

  1. Missing Return Type (MissingReturnDocblockFixer)

    • Adds @return annotations when return type is missing
  2. Missing Parameter Type (MissingParamDocblockFixer)

    • Adds @param annotations for parameters without types
  3. Undefined Properties (MissingPropertyDocblockFixer)

    • Adds @property or @var annotations for undefined properties
  4. Eloquent Pivot Property (UndefinedPivotPropertyFixer)

    • Adds @property-read annotation for Laravel Eloquent $pivot property
  5. Collection Generics (CollectionGenericDocblockFixer)

    • Adds generic type parameters to Collection types (e.g., Collection<int, mixed>)
  6. Undefined Variables (UndefinedVariableFixer)

    • Adds inline @var annotations for undefined variables
  7. Missing Use Statements (MissingUseStatementFixer)

    • Adds use statements for undefined classes
  8. Undefined Methods (UndefinedMethodFixer)

    • Adds @method annotations for magic methods
  9. Missing Throws Annotation (MissingThrowsDocblockFixer)

    • Adds @throws annotations when exceptions are thrown
  10. Callable Type Invocation (CallableTypeFixer)

    • Adds @param-immediately-invoked-callable or @param-later-invoked-callable annotations
  11. Mixin Annotation (MixinFixer)
    • Adds @mixin ClassName annotation for classes using magic methods (__call, __get, __set) to delegate calls

Examples

Example 1: Missing Return Type

Before:

After:

Example 2: Undefined Property

Before:

After:

Example 3: Collection Generics

Before:

After:

Configuration

The tool works out of the box with default settings. All fix strategies are enabled by default.

How It Works

  1. Runs PHPStan (or reads existing JSON output)
  2. Parses PHPStan JSON output into structured Issue objects
  3. Matches each issue to appropriate fix strategies
  4. Applies fixes using AST parsing and PHPDoc manipulation
  5. Shows preview (suggest mode) or writes changes (apply mode)

Requirements

Troubleshooting

Framework Compatibility Notice

⚠️ Important: This package is framework-agnostic and is not officially tested or supported with specific frameworks like Laravel, Symfony, etc.

If you encounter framework-specific issues, please report them via GitHub Issues.

Laravel package:discover Error

Problem: Error Call to a member function make() on null occurs during package:discover in Laravel.

Solution: In version v1.2.2+, the package has correctly configured dont-discover as an array in composer.json:

This should prevent Laravel from auto-discovering the package during package:discover.

If the problem persists:

If you still encounter the error, it may be related to how Laravel initializes the container during package:discover. In that case, you can use a workaround:

  1. Ensure you're using v1.2.2+:

  2. Check the package's composer.json in vendor/lukaszzychal/phpstan-fixer/composer.json:
    • Should be: "dont-discover": [] (array)
    • Should NOT be: "dont-discover": true (boolean)

Related Issues:

Development

Running Tests

CI/CD

The project uses GitHub Actions for continuous integration:

See .github/workflows/ for details.

Compatibility Testing

This package uses PHP Compatibility Tester to ensure compatibility across different frameworks and PHP versions:

Compatibility tests run automatically:

This automatically tests phpstan-fixer against various frameworks (Laravel 11/12, Symfony 7/8, CodeIgniter 4/5) and PHP versions (8.1-8.4) to ensure it works correctly in different environments. Test reports are available as GitHub Actions artifacts.

Initializing Compatibility Testing

To set up compatibility testing in your project:

  1. Run the init command:

  2. The command will:

    • Create .compatibility.yml configuration file
    • Copy PHPUnit test templates to tests/compatibility/
    • Copy GitHub Actions workflow to .github/workflows/compatibility-tests.yml
    • Copy test scripts to scripts/
  3. Edit .compatibility.yml to configure:
    • Your package name
    • PHP versions to test
    • Frameworks and versions
    • Test scripts to run

Note: If the example configuration file is not found in the package, you can use the example from vendor/lukaszzychal/php-compatibility-tester/tests/fixtures/test-package/.compatibility.yml as a reference.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

FAQ

What's the difference between the execution modes?

There are three ways to run the tool:

  1. vendor/bin/phpstan-fixer (default, no parameters)

    • Equivalent to --mode=suggest
    • Shows what would be changed
    • Does NOT modify files
    • Safe to run - preview only
  2. vendor/bin/phpstan-fixer --mode=suggest

    • Explicit suggest mode (same as default)
    • Shows proposed changes
    • Does NOT modify files
    • Safe to run - preview only
  3. vendor/bin/phpstan-fixer --mode=apply
    • Actually writes changes to files
    • Modifies source code
    • Use with caution - creates permanent changes

Recommendation: Always run with --mode=suggest first to preview changes before applying them.

What happens to errors that can't be fixed?

If a fixer strategy cannot automatically fix an error, it will be displayed at the end of the output in PHPStan format. These are errors that require manual intervention or are not yet supported by any fixer strategy.

License

MIT License - see LICENSE file for details.

Author

Łukasz Zychal

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

For bug reports and feature requests, please use the GitHub Issues page.


All versions of phpstan-fixer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
nikic/php-parser Version ^5.0
symfony/console Version ^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lukaszzychal/phpstan-fixer contains the following files

Loading the files please wait ...