• Stars
    star
    68
  • Rank 457,643 (Top 10 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ““ Provides a composer package with a configuration factory and rule set factories for friendsofphp/php-cs-fixer.

php-cs-fixer-config

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with a configuration factory and rule set factories for friendsofphp/php-cs-fixer.

Installation

Run

composer require --dev ergebnis/php-cs-fixer-config

Usage

Configuration

Pick one of the rule sets:

Create a configuration file .php-cs-fixer.php in the root of your project:

<?php

declare(strict_types=1);

use Ergebnis\PhpCsFixer\Config;

$ruleSet = Config\RuleSet\Php83::create();

$config = Config\Factory::fromRuleSet($ruleSet);

$config->getFinder()->in(__DIR__);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');

return $config;

Git

All configuration examples use the caching feature, and if you want to use it as well, you should add the cache directory to .gitignore:

+ /.build/
 /vendor/

Configuring a rule set with header

๐Ÿ’ก Optionally specify a header:

 <?php

 declare(strict_types=1);

 use Ergebnis\PhpCsFixer\Config;

+$header = <<<EOF
+Copyright (c) 2023 Andreas Mรถller
+
+For the full copyright and license information, please view
+the LICENSE file that was distributed with this source code.
+
+@see https://github.com/ergebnis/php-cs-fixer-config
+EOF;

-$ruleSet = Config\RuleSet\Php83::create();
+$ruleSet = Config\RuleSet\Php83::create()->withHeader($header);

 $config = Config\Factory::fromRuleSet($ruleSet);

 $config->getFinder()->in(__DIR__);
 $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');

 return $config;

This will enable and configure the HeaderCommentFixer, so that file headers will be added to PHP files, for example:

 <?php

 declare(strict_types=1);

+/**
+ * Copyright (c) 2023 Andreas Mรถller
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ *
+ * @see https://github.com/ergebnis/php-cs-fixer-config
+ */

Configuring a rule set that overrides rules

๐Ÿ’ก Optionally override rules from a rule set by passing a set of rules to be merged in:

 <?php

 declare(strict_types=1);

 use Ergebnis\PhpCsFixer\Config;

-$ruleSet = Config\RuleSet\Php83::create();
+$ruleSet = Config\RuleSet\Php83::create()->withRules(Config\Rules::fromArray([
+    'mb_str_functions' => false,
+    'strict_comparison' => false,
+]));

 $config = Config\Factory::fromRuleSet($ruleSet);

 $config->getFinder()->in(__DIR__);
 $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');

 return $config;

Configuring a rule set that registers and configures rules for custom fixers

๐Ÿ’ก Optionally register and configure rules for custom fixers:

 <?php

 declare(strict_types=1);

 use Ergebnis\PhpCsFixer\Config;
 use FooBar\Fixer;

-$ruleSet = Config\RuleSet\Php83::create();
+$ruleSet = Config\RuleSet\Php83::create()
+    ->withCustomFixers(Config\Fixers::fromFixers(
+        new Fixer\BarBazFixer(),
+        new Fixer\QuzFixer(),
+    ))
+    ->withRules(Config\Rules::fromArray([
+        'FooBar/bar_baz' => true,
+        'FooBar/quz' => [
+            'qux => false,
+        ],
+    ]))
+]);

 $config = Config\Factory::fromRuleSet($ruleSet);

 $config->getFinder()->in(__DIR__);
 $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');

 return $config;

Makefile

If you like Makefiles, create a Makefile with a coding-standards target:

+.PHONY: coding-standards
+coding-standards: vendor
+    mkdir -p .build/php-cs-fixer
+    vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --show-progress=dots --verbose

 vendor: composer.json composer.lock
     composer validate
     composer install

Run

make coding-standards

to automatically fix coding standard violations.

Composer script

If you like composer scripts, add a coding-standards script to composer.json:

 {
   "name": "foo/bar",
   "require": {
     "php": "^8.1",
   },
   "require-dev": {
     "ergebnis/php-cs-fixer-config": "^6.21.0"
+  },
+  "scripts": {
+    "coding-standards": [
+      "mkdir -p .build/php-cs-fixer",
+      "php-cs-fixer fix --diff --show-progress=dots --verbose"
+    ]
   }
 }

Run

composer coding-standards

to automatically fix coding standard violations.

GitHub Actions

If you like GitHub Actions, add a coding-standards job to your workflow:

 on:
   pull_request: null
   push:
     branches:
       - main

 name: "Integrate"

 jobs:
+  coding-standards:
+    name: "Coding Standards"
+
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        php-version:
+          - "8.1"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+
+      - name: "Set up PHP"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          coverage: "none"
+          php-version: "${{ matrix.php-version }}"
+
+      - name: "Cache dependencies installed with composer"
+        uses: "actions/cache@v2"
+        with:
+          path: "~/.composer/cache"
+          key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
+          restore-keys: "php-${{ matrix.php-version }}-composer-"
+
+      - name: "Install locked dependencies with composer"
+        run: "composer install --ansi --no-interaction --no-progress --no-suggest"
+
+      - name: "Create cache directory for friendsofphp/php-cs-fixer"
+        run: mkdir -p .build/php-cs-fixer
+
+      - name: "Cache cache directory for friendsofphp/php-cs-fixer"
+        uses: "actions/cache@v2"
+        with:
+          path: "~/.build/php-cs-fixer"
+          key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}"
+          restore-keys: |
+            php-${{ matrix.php-version }}-php-cs-fixer-main
+            php-${{ matrix.php-version }}-php-cs-fixer-
+
+      - name: "Run friendsofphp/php-cs-fixer"
+        run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --show-progress=dots --verbose"

Changelog

The maintainers of this project record notable changes to this project in a changelog.

Contributing

The maintainers of this project suggest following the contribution guide.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this project provide limited support.

You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.

PHP Version Support Policy

This project supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy

This project has a security policy.

License

This project uses the MIT license.

Credits

This project is inspired by and also replaces localheinz/php-cs-fixer-config.

This project requires and enables custom fixers from the following packages:

Social

Follow @localheinz and @ergebnis on Twitter.

More Repositories

1

composer-normalize

๐ŸŽต Provides a composer plugin for normalizing composer.json.
PHP
1,035
star
2

phpstan-rules

๐Ÿ‘“ Provides a composer package with rules for phpstan/phpstan.
PHP
345
star
3

php-package-template

:octocat: + ๐Ÿ“’ Provides a GitHub repository template for a composer package with GitHub Actions workflows using standard PHP development tools.
PHP
303
star
4

phpunit-slow-test-detector

โฑ๏ธ Provides a composer package with an extension for detecting slow tests in phpunit/phpunit.
PHP
115
star
5

http-method

๐Ÿ“Ÿ Provides a composer package with constants for HTTP request methods.
PHP
92
star
6

json-printer

๐Ÿ“ƒ Provides a composer package with a JSON printer, allowing for flexible indentation.
PHP
86
star
7

factory-bot

๐Ÿค– Provides a composer package with a fixture factory for doctrine/orm entities.
PHP
78
star
8

json-normalizer

๐Ÿ“ƒ Provides a composer package with generic and vendor-specific normalizers for normalizing JSON documents.
PHP
76
star
9

github-changelog

:octocat: Provides a command line tool that generates a changelog based on titles of pull requests merged between specified references.
PHP
47
star
10

environment-variables

๐ŸŒณ Provides a composer package with an abstraction of environment variables.
PHP
39
star
11

classy

๐Ÿ” Provides a composer package with a finder for classy constructs (classes, enums, interfaces, and traits).
PHP
33
star
12

clock

โฐ Provides a composer package with abstractions of a clock.
PHP
30
star
13

json-schema-validator

๐Ÿ“ƒ Provides a composer package with a JSON schema validator, building on top of justinrainbow/json-schema.
PHP
30
star
14

data-provider

๐Ÿ‘“ Provides a composer package with generic data providers for use with phpunit/phpunit.
PHP
27
star
15

composer-normalize-action

:octocat: + ๐ŸŽต Provides a GitHub action for running ergebnis/composer-normalize.
Makefile
26
star
16

composer-json-normalizer

๐ŸŽต Provides normalizers for normalizing composer.json.
PHP
20
star
17

json

๐Ÿ“ƒ Provides a composer package with a Json value object for representing a valid JSON string.
PHP
20
star
18

.github

โค๏ธ Provides default community health files and composite actions for the @ergebnis organization.
Shell
18
star
19

version

๐Ÿ’พ Provides a composer package with an abstraction of a semantic version.
PHP
17
star
20

symfony-application-template

:octocat: + ๐ŸŽผ Provides a GitHub template repository for a Symfony application, using GitHub Actions.
PHP
16
star
21

test-util

๐Ÿ‘“ Provides utilities for tests.
PHP
15
star
22

json-pointer

๐Ÿ“ƒ Provides a composer package with an abstraction of a JSON pointer.
PHP
15
star
23

license

๐Ÿ’ผ Provides a composer package with an abstraction of an open-source license.
PHP
14
star
24

php-cs-fixer-config-template

:octocat: + ๐Ÿ““ Provides a GitHub repository template for a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
PHP
11
star
25

composer-root-version-action

:octocat: + ๐ŸŽต Provides a GitHub Action that sets a COMPOSER_ROOT_VERSION environment variable from the value of the branch alias defined in composer.json.
Shell
10
star
26

factory-girl-definition

๐Ÿ‘ง Provides an interface for, and an easy way to find and register entity definitions for breerly/factory-girl-php.
PHP
9
star
27

day-one-to-obsidian-converter

๐Ÿ““ Provides a composer package with a console command for converting DayOne journals to Obsidian notes.
PHP
8
star
28

rector-rules

๐Ÿ‘“ Provides a composer package with rules for rector/rector.
PHP
6
star
29

keep-a-changelog

๐Ÿ““ Provides a composer package with tools for keeping a changelog.
PHP
5
star
30

front-matter

๐Ÿ‘€ Provides a composer package with a front-matter parser.
PHP
4
star
31

factory-bot-example

๐Ÿค– + ๐Ÿ“” Provides usage examples for ergebnis/factory-bot.
PHP
4
star
32

phpunit-framework-constraint

๐Ÿ‘“ Provides additional constraints and assertions for phpunit/phpunit
PHP
4
star
33

laravel-application-template

:octocat: + ๐Ÿ“’ Provides a GitHub repository template for a Laravel application, using GitHub Actions.
PHP
3
star
34

json-normalize

๐Ÿ“ƒ Provides a composer package with a console command for normalizing JSON documents.
PHP
3
star
35

faker-provider

๐Ÿ™ Provides additional providers for fzaninotto/faker.
PHP
3
star
36

twig-front-matter

๐ŸŒฑ + ๐Ÿ‘€ Provides a composer package with a Twig loader for files with YAML front-matter.
PHP
2
star
37

playground

๐Ÿ€ A playground.
PHP
2
star
38

rector-config-template

๐Ÿ‘“ Provides a GitHub repository template for a composer package with a configuration factory and custom rule sets for rector/rector.
PHP
2
star
39

factory-muffin-definition

๐Ÿ‘ง Provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin.
PHP
2
star
40

version-constraint

๐ŸŽš๏ธ Provides a composer package with abstractions of version constraints.
PHP
1
star
41

data-generator

๐Ÿ—„ Provides a composer package with data generators.
PHP
1
star