Adding laravel/pint and nunomaduro/larastan into your Laravel project using composer with --dev prefix. For both tools, we need to have configuration files, pint.json and phpstan.neon.dist in order to work.

The minimal configuration for pint would look like:

{
    "preset": "laravel"
}

And for larastan, following configuration is recommended:

includes:
    - ./vendor/nunomaduro/larastan/extension.neon

parameters:

    paths:
        - app/

    # Level 9 is the highest level
    level: 5

Once added, we need to place the following bash script into .githooks/pre-commit file, so we can analyse and patch the files that developers recently updated:

#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM -- '*.php');

if [ -n "$files"]; then
    echo "Running laravel/pint fixes"
	./vendor/bin/pint --config pint.json $files

    git add $files

    echo "Running phpstan checks..."

    ./vendor/bin/phpstan analyse --memory-limit 1G -c phpstan.neon.dist $files

    status=$?

    if [ $status -ne 0]; then
        echo "phpstan analysis filed. Commit aborted."
        exit $status
    fi
fi