Skip to content

Commit 94f3a47

Browse files
committed
allow php8 and upgrade to cs-fixer 3.0
1 parent 7a1050c commit 94f3a47

File tree

5 files changed

+45
-89
lines changed

5 files changed

+45
-89
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
composer.lock
22
vendor/*
3-
.php_cs.cache
3+
.php-cs-fixer.cache
44

.php_cs .php-cs-fixer.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*
99
* @see https://bushbaby.nl/
1010
*
11-
* @copyright Copyright (c) 2016-2019 prooph software GmbH <[email protected]>
12-
* @copyright Copyright (c) 2016-2019 Sascha-Oliver Prolic <[email protected]>.
13-
* @copyright Copyright (c) 2010-2019 bushbaby multimedia. (https://bushbaby.nl)
11+
* @copyright Copyright (c) 2016-2021 prooph software GmbH <[email protected]>
12+
* @copyright Copyright (c) 2016-2021 Sascha-Oliver Prolic <[email protected]>.
13+
* @copyright Copyright (c) 2010-2021 bushbaby multimedia. (https://bushbaby.nl)
1414
* @author Bas Kamer <[email protected]>
1515
* @license MIT
1616
*
@@ -20,10 +20,10 @@
2020
declare(strict_types=1);
2121

2222
$config = new \Bsb\CS\Config();
23-
$config->getFinder()->in(__DIR__)->exclude([])->append(['.php_cs']);
23+
$config->getFinder()->in(__DIR__)->exclude([])->append(['.php-cs-fixer.php']);
2424

25-
$cacheDir = \getenv('TRAVIS') ? \getenv('HOME') . '/.php-cs-fixer' : __DIR__;
25+
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
2626

27-
$config->setCacheFile($cacheDir . '/.php_cs.cache');
27+
$config->setCacheFile($cacheDir . '/.php-cs-fixer.cache');
2828

2929
return $config;

README.md

+7-53
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $ composer require --dev bushbaby/php-cs-fixer-config
1616

1717
### Configuration
1818

19-
Create a configuration file `.php_cs` in the root of your project:
19+
Create a configuration file `.php-cs-fixer.php` in the root of your project:
2020

2121
```php
2222
<?php
@@ -26,23 +26,23 @@ $config->getFinder()->in(__DIR__);
2626

2727
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
2828

29-
$config->setCacheFile($cacheDir . '/.php_cs.cache');
29+
$config->setCacheFile($cacheDir . '/.php-cs-fixer.cache');
3030

3131
return $config;
3232
```
3333

3434
### Git
3535

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

3838
```
3939
vendor/
40-
.php_cs.cache
40+
.php-cs-fixer.cache
4141
```
4242

4343
### Travis
4444

45-
Update your `.travis.yml` to cache the `php_cs.cache` file:
45+
Update your `.travis.yml` to cache the `.php-cs-fixer` directory:
4646

4747
```yml
4848
cache:
@@ -54,12 +54,12 @@ Then run `php-cs-fixer` in the `script` section:
5454

5555
```yml
5656
script:
57-
- vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run
57+
- vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --verbose --diff --dry-run
5858
```
5959

6060
### GitLab
6161

62-
Update your `.gitlab-ci` to cache the `php_cs.cache` file:
62+
Update your `.gitlab-ci` to cache the `.php-cs-fixer.cache` file:
6363

6464
```
6565
script:
@@ -76,52 +76,6 @@ If you need to fix issues locally, just run
7676
$ ./vendor/bin/php-cs-fixer fix -v
7777
```
7878
79-
### Pre-commit hook
80-
81-
You can add a `pre-commit` hook
82-
83-
```
84-
$ touch .git/pre-commit && chmod +x .git/pre-commit
85-
```
86-
87-
Paste this into `.git/pre-commit`:
88-
89-
```bash
90-
#!/usr/bin/env bash
91-
92-
echo "pre commit hook start"
93-
94-
CURRENT_DIRECTORY=`pwd`
95-
GIT_HOOKS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
96-
97-
PROJECT_DIRECTORY="$GIT_HOOKS_DIR/../.."
98-
99-
cd $PROJECT_DIRECTORY;
100-
PHP_CS_FIXER="vendor/bin/php-cs-fixer"
101-
102-
HAS_PHP_CS_FIXER=false
103-
104-
if [ -x "$PHP_CS_FIXER" ]; then
105-
HAS_PHP_CS_FIXER=true
106-
fi
107-
108-
if $HAS_PHP_CS_FIXER; then
109-
git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do
110-
${PHP_CS_FIXER} fix --config-file=.php_cs --verbose ${line};
111-
git add "$line";
112-
done
113-
else
114-
echo ""
115-
echo "Please install php-cs-fixer, e.g.:"
116-
echo ""
117-
echo " composer require friendsofphp/php-cs-fixer:2.0.0"
118-
echo ""
119-
fi
120-
121-
cd $CURRENT_DIRECTORY;
122-
echo "pre commit hook finish"
123-
```
124-
12579
## License
12680
12781
This package is licensed using the MIT License.

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^7.1",
23-
"friendsofphp/php-cs-fixer": "^2.1"
22+
"php": "^7.1.3 || ^8.0",
23+
"friendsofphp/php-cs-fixer": "^3.0"
2424
},
2525
"autoload": {
2626
"psr-4": {
2727
"Bsb\\CS\\": "src"
2828
}
29+
},
30+
"scripts": {
31+
"php-check": "php-cs-fixer fix --dry-run",
32+
"php-fix": "php-cs-fixer fix"
2933
}
3034
}

src/Config.php

+25-27
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*
99
* @see https://bushbaby.nl/
1010
*
11-
* @copyright Copyright (c) 2016-2019 prooph software GmbH <[email protected]>
12-
* @copyright Copyright (c) 2016-2019 Sascha-Oliver Prolic <[email protected]>.
13-
* @copyright Copyright (c) 2010-2019 bushbaby multimedia. (https://bushbaby.nl)
11+
* @copyright Copyright (c) 2016-2021 prooph software GmbH <[email protected]>
12+
* @copyright Copyright (c) 2016-2021 Sascha-Oliver Prolic <[email protected]>.
13+
* @copyright Copyright (c) 2010-2021 bushbaby multimedia. (https://bushbaby.nl)
1414
* @author Bas Kamer <[email protected]>
1515
* @license MIT
1616
*
@@ -33,13 +33,9 @@ class Config extends PhpCsFixerConfig
3333
'@PSR2' => true,
3434
'@Symfony' => true,
3535
'array_syntax' => ['syntax' => 'short'],
36-
'binary_operator_spaces' => [
37-
'align_double_arrow' => false,
38-
'align_equals' => false,
39-
],
40-
'blank_line_after_namespace' => true,
36+
'blank_line_after_namespace' => true,
4137
'blank_line_after_opening_tag' => true,
42-
'blank_line_before_return' => true,
38+
'blank_line_before_statement' => true,
4339
'braces' => true,
4440
'cast_spaces' => true,
4541
'class_definition' => true,
@@ -51,9 +47,9 @@ class Config extends PhpCsFixerConfig
5147
'full_opening_tag' => true,
5248
'function_declaration' => true,
5349
'function_typehint_space' => true,
54-
'hash_to_slash_comment' => true,
50+
'single_line_comment_style' => true,
5551
'header_comment' => [
56-
'commentType' => 'PHPDoc',
52+
'comment_type' => 'PHPDoc',
5753
'header' => 'Bushbaby was here at `%package%` in `%year%`! Please create a .docheader in the project root and run `composer cs-fix`',
5854
'location' => 'after_open',
5955
'separate' => 'both',
@@ -62,10 +58,10 @@ class Config extends PhpCsFixerConfig
6258
'indentation_type' => true,
6359
'line_ending' => true,
6460
'linebreak_after_opening_tag' => true,
65-
'lowercase_constants' => true,
61+
'constant_case' => true,
6662
'lowercase_keywords' => true,
6763
'method_argument_space' => true,
68-
'method_separation' => true,
64+
'class_attributes_separation' => true,
6965
'modernize_types_casting' => true,
7066
'native_function_casing' => true,
7167
'native_function_invocation' => true,
@@ -74,13 +70,13 @@ class Config extends PhpCsFixerConfig
7470
'no_blank_lines_after_class_opening' => true,
7571
'no_closing_tag' => true,
7672
'no_empty_statement' => true,
77-
'no_extra_consecutive_blank_lines' => true,
73+
'no_extra_blank_lines' => true,
7874
'no_leading_import_slash' => true,
7975
'no_leading_namespace_whitespace' => true,
8076
'no_multiline_whitespace_around_double_arrow' => true,
81-
'no_multiline_whitespace_before_semicolons' => true,
77+
'multiline_whitespace_before_semicolons' => true,
8278
'no_short_bool_cast' => true,
83-
'no_short_echo_tag' => true,
79+
'echo_tag_syntax' => ['format' => 'long'],
8480
'no_singleline_whitespace_before_semicolons' => true,
8581
'no_spaces_around_offset' => true,
8682
'no_spaces_inside_parenthesis' => true,
@@ -99,8 +95,10 @@ class Config extends PhpCsFixerConfig
9995
'object_operator_without_whitespace' => true,
10096
'ordered_imports' => true,
10197
'phpdoc_indent' => true,
102-
'phpdoc_inline_tag' => true,
103-
'psr4' => true,
98+
'general_phpdoc_tag_rename' => true,
99+
'phpdoc_inline_tag_normalizer' => true,
100+
'phpdoc_tag_type' => true,
101+
'psr_autoloading' => true,
104102
'return_type_declaration' => true,
105103
'semicolon_after_instruction' => true,
106104
'short_scalar_cast' => true,
@@ -115,7 +113,7 @@ class Config extends PhpCsFixerConfig
115113
'switch_case_semicolon_to_colon' => true,
116114
'switch_case_space' => true,
117115
'ternary_operator_spaces' => true,
118-
'trailing_comma_in_multiline_array' => true,
116+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
119117
'trim_array_spaces' => true,
120118
'unary_operator_spaces' => true,
121119
'visibility_required' => true,
@@ -126,7 +124,7 @@ public function __construct(array $overrides = [])
126124
{
127125
parent::__construct('bushbaby php-cs-fixer-config');
128126

129-
$this->setRules(\array_merge($this->defaults, $overrides));
127+
$this->setRules(array_merge($this->defaults, $overrides));
130128
$this->setRiskyAllowed(true);
131129
}
132130

@@ -141,23 +139,23 @@ public function getRules(): array
141139

142140
private function headerComment(array $rules): array
143141
{
144-
if (\file_exists('.docheader')) {
145-
$header = \file_get_contents('.docheader');
142+
if (file_exists('.docheader')) {
143+
$header = file_get_contents('.docheader');
146144
} else {
147145
$header = $rules['header'];
148146
}
149147

150148
// remove comments from existing .docheader or crash
151-
$header = \str_replace(['/**', ' */', ' * ', ' *'], '', $header);
149+
$header = str_replace(['/**', ' */', ' * ', ' *'], '', $header);
152150
$package = 'unknown';
153151

154-
if (\file_exists('composer.json')) {
155-
$package = \json_decode(\file_get_contents('composer.json'))->name ?? 'unknown/unknown';
152+
if (file_exists('composer.json')) {
153+
$package = json_decode(file_get_contents('composer.json'))->name ?? 'unknown/unknown';
156154
}
157155

158-
$header = \str_replace(['%package%', '%year%'], [$package, (new \DateTime('now'))->format('Y')], $header);
156+
$header = str_replace(['%package%', '%year%'], [$package, (new \DateTime('now'))->format('Y')], $header);
159157

160-
$rules['header'] = \trim($header);
158+
$rules['header'] = trim($header);
161159

162160
return $rules;
163161
}

0 commit comments

Comments
 (0)