Search by

framesnpictures / el-code-format

chris97pl

PHP-CS-Fixer configuration replicating Laravel Pint, with custom rules

Package info

github.com/FramesNPictures/el-code-format

pkg:composer/framesnpictures/el-code-format

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.3 2026-10-12 10:59 UTC

This package is auto-updated.

Last update: 2026-10-12 10:59:58 UTC


README

A PHP-CS-Fixer configuration that formats code the same way as Laravel Pint, using the laravel preset plus the FramesNPictures rules. It also adds custom rules that Pint can't run.

Rule Risky Description
Fnp/ordered_int_backed_enum_cases yes Sorts the cases of int backed enums by value.

Installation

composer require --dev framesnpictures/el-code-format

Create .php-cs-fixer.dist.php in the project root:

<?php

use Fnp\CodeFormat\Config;

return new Config;

Then run vendor/bin/php-cs-fixer fix, or vendor/bin/php-cs-fixer check in CI.

Configuration

Config is a PhpCsFixer\Config with the following settings already applied:

  • Rules: the Pint laravel preset (Preset::laravel()), then the FramesNPictures rules on top (Preset::fnp()), which also turn on the custom rules. The FramesNPictures rules replace whole preset rules, the same way Pint merges pint.json.
  • Finder: the current working directory, skipping the same files as Pint: vendor, bootstrap/cache, build, node_modules, storage, IDE helper files, Blade templates and dot files.
  • Other settings: risky rules allowed, cache on, parallel runs, and unsupported PHP versions allowed.

Override rules or the path:

return (new Config(path: __DIR__ . '/src'))
    ->mergeRules([
        'Fnp/ordered_int_backed_enum_cases' => ['direction' => 'descending'],
        'concat_space' => ['spacing' => 'none'],
    ]);

To change the finder, call getFinder() (for example $config->getFinder()->exclude('tests/Fixtures')) or replace it with setFinder().

Pint parity

tests/PintParityTest.php formats the fixtures in tests/Fixtures/parity with Pint, configured by tests/Fixtures/pint.json, and with this config, and expects the same output. When Pint changes its preset, refresh Preset::laravel() from Pint's resources/presets/laravel.php.

The FramesNPictures rules include new_with_braces, which php-cs-fixer has deprecated, so every run prints a deprecation notice. The rule stays in so the output matches Pint.

Fnp/ordered_int_backed_enum_cases

Orders the cases of int backed enums by their value.

 enum Flag: int
 {
-    case Write = 1 << 1;
-    case Read = 1 << 0; // r
     case None = 0;
+    case Read = 1 << 0; // r
+    case Write = 1 << 1;
 }
  • Only the positions taken by cases change. Constants, trait imports and methods stay where they are.
  • Comments, docblocks and attributes in front of a case move with it, and so does a comment on the same line after it.
  • The fixer works out case values written as integer literals (decimal, hex, octal, binary and _ separators) or as constant expressions built from them with ( ) - + ~ * % << >> & ^ |. If any case refers to something else, such as self::OTHER or Foo::BAR, the whole enum is skipped.
  • Cases with the same value keep their original order.
  • String backed and pure enums are ignored.
  • The rule is risky because it changes the order of Enum::cases().

Options

Option Values Default
direction ascending, descending ascending
'Fnp/ordered_int_backed_enum_cases' => ['direction' => 'descending'],