Description

Latest Version on Packagist Total Downloads

This package is a Laravel Pint preset for Proxify projects.

Installation

You can install the package via composer:

composer require proxify/proxify-php-code-style --dev

Usage

Command line

// checks new and modified files if they follow coding standar
sh vendor/bin/proxify-cs-checker
// fixes all project php files
php vendor/bin/proxify-cs-fixer
// fixes selected path files
php vendor/bin/proxify-cs-fixer app/Models
// fixes selected files
php vendor/bin/proxify-cs-fixer app/Models/User.php app/Models/Developer.php

These commands will use proxify code style rules by default, which are made on top of laravel preset. For more details you can check laravel pint docs Although it's not recommended, you still can use laravel pint commands directly as well as custom pint.json config file.

Windows users

To prevent Git from automatically changing line endings, please modify your Git configuration.

git config --global core.autocrlf input

This will change CRLF line separator to LF. ( Linux based )

VSCode setup

Install Laravel pint plugin: https://marketplace.visualstudio.com/items?itemName=open-southeners.laravel-pint

Add code style config path to .vscode/settings.json

"laravel-pint.configPath": "vendor/proxify/proxify-php-code-style/pint.json"

PHPStorm setup

Create a new File watcher.

// Pint file watcher settings
$ProjectFileDir$/vendor/bin/proxify-cs-fixer
$FileRelativePath$
$FileRelativePath$
$ProjectFileDir$
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Watchers config

To make phpstorm ctrl+alt+L hotkey work similar to pint configs, adjust code style by setting laravel and update

“Wrapping and Braces“->”Array initializer”->“align key-value pairs”

“Spaces“->”Around operators”->”Concatenation(.)”

Editor Configs

Disable PHP in the reformat code setting. reformat-code.jpg

Source Article

Laracasts Video

Github actions job

create a file in .github/workflows/laravel_checks.yml or add the below step to your existing jobs workflow

  laravel-code-style:
    name: Code Style
    if: github.ref_name != 'master'
    runs-on: "ubuntu-20.04"
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Cache Composer cache directory
        uses: actions/cache@v2
        with:
          path: ~/.composer/cache/files
          key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "${{ env.php_version }}"
          extensions: "${{ env.php_extensions }}"
          tools: composer:v2.4

      - name: Install dependencies
        run: composer install --no-scripts --no-progress --no-suggest --prefer-dist --optimize-autoloader

      - name: Code style check
        run: |
          sh ./vendor/bin/proxify-cs-checker

Errors

If you get an error like this:

env: php: No such file or directory

Process finished with exit code 127

Remove value of Environment variables, in the Pint File Watcher settings.

Pre-commit testing

install pre-commit on your PC then run the command below on your project root to enable pre-commit hook

 pre-commit install

Add this to your .pre-commit-config.yaml

repos:
  - repo: local
    hooks:
      - id: laravel-pint
        name: laravel-pint
        entry: ./vendor/bin/proxify-cs-pre-commit
        language: script
        types: [php]
        pass_filenames: false

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email maxime.le.roy@proxify.io instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.