Skip to content

Latest commit

 

History

History
80 lines (70 loc) · 2.84 KB

README.md

File metadata and controls

80 lines (70 loc) · 2.84 KB

Latest Stable Version

moxio/captainhook-psalm

This project is a plugin for CaptainHook to check your staged PHP files for errors using Psalm. The commit is blocked when one or more errors is detected in any of the staged PHP files.

Installation

Install as a development dependency using composer:

$ composer require --dev moxio/captainhook-psalm

Usage

Add Psalm error checking as a pre-commit-hook to your captainhook.json configuration file:

{
    "pre-commit": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Moxio\\CaptainHook\\Psalm\\PsalmCheckAction"
            }
        ]
    }
}

The check is only run when committing changes to PHP files. It will thus not detect pre-existing errors in PHP files which are not staged.

The action expects Psalm to be installed as a local Composer package (i.e. available at vendor/vimeo/psalm).

Conditional usage

If you want to perform Psalm-error checks only when Psalm is installed (i.e. available at vendor/vimeo/psalm), you can add a corresponding condition to the action:

{
    "pre-commit": {
        "enabled": true,
        "actions": [
            {
                "action": "\\Moxio\\CaptainHook\\Psalm\\PsalmCheckAction",
                "conditions": [
                    {
                        "exec": "\\Moxio\\CaptainHook\\Psalm\\Condition\\PsalmInstalled"
                    }
                ]
            }
        ]
    }
}

This may be useful in scenarios where you have a shared CaptainHook configuration file that is included both in projects that use Psalm and projects that don't. If Psalm is installed, the action is run. In projects without Psalm, the validation is skipped.

Influence of projectFiles in psalm.xml

If this plugin detects a psalm.xml configuration file, this plugin will try to use the projectFiles configured in that file to filter the files checked by Psalm. This is done on a best-effort basis: not all constructs possible within projectFiles are supported, but simple directories and files (along with ignoreFiles) should work fine. If you encounter a situation where files aren't properly filtered, feel free to send a PR.

Versioning

This project adheres to Semantic Versioning.

Contributing

Contributions to this project are welcome. Please make sure that your code follows the PSR-12 extended coding style.

License

This project is released under the MIT license.