Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the php-cs-fixer and enforce the formatting #9

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ jobs:

- name: Run test suite
run: composer run-script test

- name: Lint the code
env:
PHP_CS_FIXER_IGNORE_ENV: '1' # make cs-fixer stop complaining when using PHP 8.3
run: composer run-script lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.phpunit.result.cache
.phpunit.cache
example.php
.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src/')
->in(__DIR__ . '/tests/')
;

$config = new PhpCsFixer\Config();

// https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/index.rst
// https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst
return $config
->setRules([
'@PSR2' => true,
])
->setFinder($finder)
;
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^10.3"
"phpunit/phpunit": "^10.3",
"friendsofphp/php-cs-fixer": "^3.22"
},
"scripts": {
"test": "phpunit --testdox"
"test": "phpunit --testdox",
"lint": [
"php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --verbose"
],
"format": [
"php-cs-fixer fix --config=.php-cs-fixer.php"
]
}
}
Loading