Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Cs Fixer Config Laravel Package

coffreo/php-cs-fixer-config

View on GitHub
Deep Wiki
Context7

php-cs-fixer-config

All credits goes to localheinz/php-cs-fixer-config.

This project is a fork with Coffreo rules and few changes to:

  • add header template feature
  • add reading of composer.json datas to fullfill header template
  • handle multiples version of php-cs-fixer in tests

This repository provides a configuration factory and multiple Coffreo rule sets for friendsofphp/php-cs-fixer.

Installation

Run

$ composer require --dev coffreo/php-cs-fixer-config

Usage

Configuration

Pick one of the rule sets:

  • Coffreo\PhpCsFixer\Config\RuleSet\Php54 (includes migration 5.6 rules)
  • Coffreo\PhpCsFixer\Config\RuleSet\Php54To56 (includes ONLY migration 5.6 rules)
  • Coffreo\PhpCsFixer\Config\RuleSet\Php56
  • Coffreo\PhpCsFixer\Config\RuleSet\Php70
  • Coffreo\PhpCsFixer\Config\RuleSet\Php71
  • Coffreo\PhpCsFixer\Config\RuleSet\Php72

:ledger: All configuration (except Php54To56) include @Symfony and @PSR2 rules.

Create a configuration file .php_cs in the root of your project:

<?php

use Coffreo\PhpCsFixer\Config;

// read composer
$composer = json_decode(file_get_contents(__DIR__."/composer.json"));
if (null === $composer) {
    throw new \Exception('Composer.json invalid. CS-Fixer aborted.');
}
$header = Config\HeaderHelper::coffreo(compact("composer"));

$config = Config\Factory::fromRuleSet(

    // CHOOSE YOUR RULE SET HERE
    new Config\RuleSet\Php54($header)

);
$config->getFinder()->in(__DIR__.'/src');
$config->setCacheFile(__DIR__.'/.php_cs.cache');

return $config;

Git

Add .php_cs.cache (this is the cache file created by php-cs-fixer) to .gitignore:

vendor/
.php_cs.cache

Makefile (optional)

Create a Makefile with a cs target:

.PHONY: composer cs

composer:
	composer validate
	composer install

cs: composer
	vendor/bin/php-cs-fixer fix --config=.php_cs --diff --verbose

:bulb: This can either be done with other scripting launcher (npm run .. or composer run-script ..)

Developer commands

Few commands to know when updating this project:

$ make test   # run PHPUnit test suite
$ make cs     # Apply CS to source code (THIS MUST BE DONE BEFORE PUSHING)
$ make        # lazy ? execute both above commands

FAQ

  • I've installed everything but it keeps me warning that few rules are inexistents.

You get thie error message because the version of friendsofphp/php-cs-fixer is not appropriate with selected rules set. Two potentials causes:

  • Ensure your ruleset is compatible with your PHP version (56 for 5.6, 70 for 7.0, etc...)
  • Check your composer.json for config.platform key. It should either be undefined or the correct value depending on your PHP version. The presence of this config key force composer to install cs-fixer version related to PHP version defined by this key, ignoring real current version of PHP.)
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields
splash/sonata-admin
splash/metadata