Skip to content

Commit

Permalink
Do not require PHP CS Fixer (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Mar 18, 2022
1 parent 41456cc commit 6257b92
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 6 deletions.
28 changes: 28 additions & 0 deletions .dev-tools/autoload.php
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

/*
* This file is part of PHP CS Fixer: custom fixers.
*
* (c) 2018 Kuba Werłos
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

if (interface_exists('PhpCsFixer\\Fixer\\FixerInterface')) {
return; // all good, PHP CS Fixer is here
}

$phar = __DIR__ . '/../vendor/php-cs-fixer/shim/php-cs-fixer';
if (file_exists($phar)) {
$pharLoaded = Phar::loadPhar($phar, 'php-cs-fixer.phar');
if (!$pharLoaded) {
exit(sprintf('Phar "%s" not loaded!' . PHP_EOL, $phar));
}

require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';

return;
}

require_once __DIR__ . '/vendor/autoload.php';
5 changes: 5 additions & 0 deletions .dev-tools/src/Readme/ReadmeCommand.php
Expand Up @@ -154,6 +154,11 @@ private function usage(): string
```diff
%s
```
:warning: When PHP CS Fixer is installed via [`php-cs-fixer/shim`](https://github.com/PHP-CS-Fixer/shim) package,
requiring autoload is needed to load `PhpCsFixerCustomFixers` classes:
```php
require_once __DIR__ . \'/vendor/autoload.php\';
```
',
$this->diff(
\file_get_contents(__DIR__ . '/php-cs-fixer.config.before.php'),
Expand Down
22 changes: 18 additions & 4 deletions .github/workflows/ci.yaml
Expand Up @@ -17,37 +17,52 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- run: composer require friendsofphp/php-cs-fixer --no-update
- run: composer update --no-progress
- run: composer analyse

test:
name: PHP ${{ matrix.php-version }} ${{ matrix.description }}
name: PHP ${{ matrix.php-version }} with ${{ matrix.with-package }} ${{ matrix.description }}
strategy:
fail-fast: false
matrix:
include:
- description: 'with lowest dependencies'
os: ubuntu-latest
php-version: '7.4'
with-package: friendsofphp/php-cs-fixer:*
composer-flags: '--prefer-lowest'
- description: 'with lowest dependencies'
os: ubuntu-latest
php-version: '7.4'
with-package: php-cs-fixer/shim:*
composer-flags: '--prefer-lowest'
- os: ubuntu-latest
php-version: '8.0'
with-package: friendsofphp/php-cs-fixer:*
- os: ubuntu-latest
php-version: '8.1'
with-package: friendsofphp/php-cs-fixer:*
coverage-driver: pcov
description: 'with calculating code coverage'
- os: ubuntu-latest
php-version: '8.1'
install-fixer-from-master-branch: true
with-package: friendsofphp/php-cs-fixer:dev-master
description: 'with PHP CS Fixer from master'
- os: ubuntu-latest
php-version: '8.1'
with-package: php-cs-fixer/shim:*
- description: on macOS
os: macos-latest
php-version: '8.1'
with-package: friendsofphp/php-cs-fixer:*
- description: on Windows
os: windows-latest
php-version: '8.1'
with-package: friendsofphp/php-cs-fixer:*
- os: ubuntu-latest
php-version: '8.2'
with-package: friendsofphp/php-cs-fixer:*
composer-flags: '--ignore-platform-reqs'
runs-on: ${{ matrix.os }}
timeout-minutes: 10
Expand All @@ -66,8 +81,7 @@ jobs:
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- if: matrix.install-fixer-from-master-branch
run: composer require friendsofphp/php-cs-fixer:dev-master --no-update
- run: composer require ${{ matrix.with-package }} --no-update
- run: composer update --no-progress ${{ matrix.composer-flags }}
- run: composer test -- --coverage-clover=./build/logs/clover.xml
- if: matrix.coverage-driver == 'pcov'
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Expand Up @@ -10,6 +10,7 @@
*/

require_once __DIR__ . '/vendor/autoload.php';

$rules = (new PhpCsFixerConfig\Rules\LibraryRules('PHP CS Fixer: custom fixers', 'Kuba Werłos', 2018))->getRules();

$rules[PhpCsFixerCustomFixers\Fixer\NoSuperfluousConcatenationFixer::name()] = ['allow_preventing_trailing_spaces' => true];
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# CHANGELOG for PHP CS Fixer: custom fixers

## v3.10.0
- Do not require `friendsofphp/php-cs-fixer` as dependency (to allow using `php-cs-fixer/shim`)

## v3.9.0
- Add PhpdocTypesCommaSpacesFixer

Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,11 @@ In your PHP CS Fixer configuration register fixers and use them:
+ PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
]);
```
:warning: When PHP CS Fixer is installed via [`php-cs-fixer/shim`](https://github.com/PHP-CS-Fixer/shim) package,
requiring autoload is needed to load `PhpCsFixerCustomFixers` classes:
```php
require_once __DIR__ . '/vendor/autoload.php';
```


## Fixers
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -12,12 +12,14 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-filter": "*",
"ext-tokenizer": "*",
"friendsofphp/php-cs-fixer": "^3.6.0"
"ext-tokenizer": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.5.3 || ^9.1.1"
},
"conflict": {
"friendsofphp/php-cs-fixer": "<3.6.0"
},
"autoload": {
"psr-4": {
"PhpCsFixerCustomFixers\\": "src"
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Expand Up @@ -2,6 +2,7 @@

<phpunit xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='./vendor/phpunit/phpunit/phpunit.xsd'
bootstrap='.dev-tools/autoload.php'
cacheResult='false'
colors='true'
executionOrder='default'
Expand Down

0 comments on commit 6257b92

Please sign in to comment.