Skip to content

Laravel Pint

Laravel Pint is the code formatter used by the CPR backend. It provides opinionated PHP code formatting based on PHP-CS-Fixer.

Usage

bash
# Format all files
composer pint
# or
vendor/bin/pint

# Preview changes without applying
vendor/bin/pint --test

# Format specific files or directories
vendor/bin/pint app/Services/

# Show verbose output
vendor/bin/pint -v

Configuration

Pint uses Laravel's default preset by default. Custom rules can be added in pint.json at the project root.

Default Preset

The Laravel preset enforces:

  • PSR-12 coding standard
  • Laravel-specific conventions
  • Consistent spacing and formatting
  • Ordered imports
  • Trailing commas in multiline arrays
  • Short array syntax []

When to Run

  • Before committing - Run composer pint to format your changes
  • In code review - Ensure all code follows the formatting standard
  • CI/CD - Run vendor/bin/pint --test to fail the build if code isn't formatted

IDE Integration

VS Code

Install the Laravel Pint extension to format on save.

PHPStorm

Configure Pint as an external tool or file watcher to auto-format.

Example

Before:

php
function example($a,$b)  {
return   $a+$b;
}

After:

php
function example($a, $b)
{
    return $a + $b;
}

CPR - Clinical Patient Records