Skip to content

Commit 6257b92

Browse files
authored
Do not require PHP CS Fixer (#757)
1 parent 41456cc commit 6257b92

File tree

8 files changed

+65
-6
lines changed

8 files changed

+65
-6
lines changed

.dev-tools/autoload.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of PHP CS Fixer: custom fixers.
5+
*
6+
* (c) 2018 Kuba Werłos
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
if (interface_exists('PhpCsFixer\\Fixer\\FixerInterface')) {
13+
return; // all good, PHP CS Fixer is here
14+
}
15+
16+
$phar = __DIR__ . '/../vendor/php-cs-fixer/shim/php-cs-fixer';
17+
if (file_exists($phar)) {
18+
$pharLoaded = Phar::loadPhar($phar, 'php-cs-fixer.phar');
19+
if (!$pharLoaded) {
20+
exit(sprintf('Phar "%s" not loaded!' . PHP_EOL, $phar));
21+
}
22+
23+
require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
24+
25+
return;
26+
}
27+
28+
require_once __DIR__ . '/vendor/autoload.php';

.dev-tools/src/Readme/ReadmeCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ private function usage(): string
154154
```diff
155155
%s
156156
```
157+
:warning: When PHP CS Fixer is installed via [`php-cs-fixer/shim`](https://github.com/PHP-CS-Fixer/shim) package,
158+
requiring autoload is needed to load `PhpCsFixerCustomFixers` classes:
159+
```php
160+
require_once __DIR__ . \'/vendor/autoload.php\';
161+
```
157162
',
158163
$this->diff(
159164
\file_get_contents(__DIR__ . '/php-cs-fixer.config.before.php'),

.github/workflows/ci.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,52 @@ jobs:
1717
- uses: shivammathur/setup-php@v2
1818
with:
1919
php-version: '8.1'
20+
- run: composer require friendsofphp/php-cs-fixer --no-update
2021
- run: composer update --no-progress
2122
- run: composer analyse
2223

2324
test:
24-
name: PHP ${{ matrix.php-version }} ${{ matrix.description }}
25+
name: PHP ${{ matrix.php-version }} with ${{ matrix.with-package }} ${{ matrix.description }}
2526
strategy:
2627
fail-fast: false
2728
matrix:
2829
include:
2930
- description: 'with lowest dependencies'
3031
os: ubuntu-latest
3132
php-version: '7.4'
33+
with-package: friendsofphp/php-cs-fixer:*
34+
composer-flags: '--prefer-lowest'
35+
- description: 'with lowest dependencies'
36+
os: ubuntu-latest
37+
php-version: '7.4'
38+
with-package: php-cs-fixer/shim:*
3239
composer-flags: '--prefer-lowest'
3340
- os: ubuntu-latest
3441
php-version: '8.0'
42+
with-package: friendsofphp/php-cs-fixer:*
3543
- os: ubuntu-latest
3644
php-version: '8.1'
45+
with-package: friendsofphp/php-cs-fixer:*
3746
coverage-driver: pcov
3847
description: 'with calculating code coverage'
3948
- os: ubuntu-latest
4049
php-version: '8.1'
41-
install-fixer-from-master-branch: true
50+
with-package: friendsofphp/php-cs-fixer:dev-master
4251
description: 'with PHP CS Fixer from master'
52+
- os: ubuntu-latest
53+
php-version: '8.1'
54+
with-package: php-cs-fixer/shim:*
4355
- description: on macOS
4456
os: macos-latest
4557
php-version: '8.1'
58+
with-package: friendsofphp/php-cs-fixer:*
4659
- description: on Windows
4760
os: windows-latest
4861
php-version: '8.1'
62+
with-package: friendsofphp/php-cs-fixer:*
4963
- os: ubuntu-latest
5064
php-version: '8.2'
65+
with-package: friendsofphp/php-cs-fixer:*
5166
composer-flags: '--ignore-platform-reqs'
5267
runs-on: ${{ matrix.os }}
5368
timeout-minutes: 10
@@ -66,8 +81,7 @@ jobs:
6681
with:
6782
path: ${{ steps.composer-cache.outputs.dir }}
6883
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
69-
- if: matrix.install-fixer-from-master-branch
70-
run: composer require friendsofphp/php-cs-fixer:dev-master --no-update
84+
- run: composer require ${{ matrix.with-package }} --no-update
7185
- run: composer update --no-progress ${{ matrix.composer-flags }}
7286
- run: composer test -- --coverage-clover=./build/logs/clover.xml
7387
- if: matrix.coverage-driver == 'pcov'

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
require_once __DIR__ . '/vendor/autoload.php';
13+
1314
$rules = (new PhpCsFixerConfig\Rules\LibraryRules('PHP CS Fixer: custom fixers', 'Kuba Werłos', 2018))->getRules();
1415

1516
$rules[PhpCsFixerCustomFixers\Fixer\NoSuperfluousConcatenationFixer::name()] = ['allow_preventing_trailing_spaces' => true];

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG for PHP CS Fixer: custom fixers
22

3+
## v3.10.0
4+
- Do not require `friendsofphp/php-cs-fixer` as dependency (to allow using `php-cs-fixer/shim`)
5+
36
## v3.9.0
47
- Add PhpdocTypesCommaSpacesFixer
58

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ In your PHP CS Fixer configuration register fixers and use them:
3333
+ PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
3434
]);
3535
```
36+
:warning: When PHP CS Fixer is installed via [`php-cs-fixer/shim`](https://github.com/PHP-CS-Fixer/shim) package,
37+
requiring autoload is needed to load `PhpCsFixerCustomFixers` classes:
38+
```php
39+
require_once __DIR__ . '/vendor/autoload.php';
40+
```
3641

3742

3843
## Fixers

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
"require": {
1313
"php": "^7.4 || ^8.0",
1414
"ext-filter": "*",
15-
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^3.6.0"
15+
"ext-tokenizer": "*"
1716
},
1817
"require-dev": {
1918
"phpunit/phpunit": "^8.5.3 || ^9.1.1"
2019
},
20+
"conflict": {
21+
"friendsofphp/php-cs-fixer": "<3.6.0"
22+
},
2123
"autoload": {
2224
"psr-4": {
2325
"PhpCsFixerCustomFixers\\": "src"

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<phpunit xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
44
xsi:noNamespaceSchemaLocation='./vendor/phpunit/phpunit/phpunit.xsd'
5+
bootstrap='.dev-tools/autoload.php'
56
cacheResult='false'
67
colors='true'
78
executionOrder='default'

0 commit comments

Comments
 (0)