Skip to content

Commit 80e042d

Browse files
authored
Add PHP-CS-Fixer (#691)
1 parent 953eef0 commit 80e042d

File tree

124 files changed

+5686
-3145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+5686
-3145
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
php: [ '8.1' ]
1616
check:
1717
- name: CS
18-
command: make cs
18+
command: make cs_lint
1919
- name: PHPStan
2020
command: make phpstan
2121

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
!/bin/php-scoper
55
!/bin/root-version.php
66
/.box_dump/
7+
/.php-cs-fixer.cache
78
/box.json
89
/build/
910
/clover.xml

.php-cs-fixer.dist.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the humbug/php-scoper package.
7+
*
8+
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
9+
* Pádraic Brady <padraic.brady@gmail.com>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
use Fidry\PhpCsFixerConfig\FidryConfig;
16+
use PhpCsFixer\Finder;
17+
18+
$finder = Finder::create()
19+
->in([
20+
'src',
21+
'tests',
22+
])
23+
->append([
24+
'bin/check-composer-root-version.php',
25+
'bin/dump-composer-root-version.php',
26+
'bin/php-scoper',
27+
'bin/root-version.php',
28+
'.php-cs-fixer.dist.php',
29+
'scoper.inc.php',
30+
]);
31+
32+
$overriddenRules = [
33+
'header_comment' => [
34+
'header' => <<<'EOF'
35+
This file is part of the humbug/php-scoper package.
36+
37+
Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
38+
Pádraic Brady <padraic.brady@gmail.com>
39+
40+
For the full copyright and license information, please view the LICENSE
41+
file that was distributed with this source code.
42+
EOF,
43+
'location' => 'after_declare_strict',
44+
],
45+
'mb_str_functions' => false,
46+
'no_unneeded_control_parentheses' => false,
47+
'yoda_style' => false,
48+
];
49+
50+
$config = new FidryConfig('', 74000);
51+
$config->addRules($overriddenRules);
52+
53+
return $config->setFinder($finder);

Makefile

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ PHP_SCOPER=$(PHP_SCOPER_BIN)
1010

1111
COMPOSER_BIN_PLUGIN_VENDOR=vendor/bamarni/composer-bin-plugin
1212

13-
CODE_SNIFFER=vendor-bin/code-sniffer/vendor/bin/phpcs
14-
CODE_SNIFFER_FIX=vendor-bin/code-sniffer/vendor/bin/phpcbf
15-
1613
PHPSTAN_BIN=vendor-bin/phpstan/vendor/bin/phpstan
1714
PHPSTAN=$(PHPSTAN_BIN) analyze src tests --level max --memory-limit=-1
1815

@@ -31,6 +28,9 @@ PHPUNIT_COVERAGE_HTML = XDEBUG_MODE=coverage $(PHPUNIT) --coverage-html=$(COVERA
3128
COVERS_VALIDATOR_BIN=vendor-bin/covers-validator/bin/covers-validator
3229
COVERS_VALIDATOR=$(COVERS_VALIDATOR_BIN)
3330

31+
PHP_CS_FIXER_BIN = vendor-bin/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer
32+
PHP_CS_FIXER = $(PHP_CS_FIXER_BIN) fix
33+
3434
BLACKFIRE=blackfire
3535

3636

@@ -58,15 +58,28 @@ update_root_version:
5858
$(MAKE) .composer-root-version
5959

6060
.PHONY: cs
61-
cs: ## Fixes CS
62-
cs: $(CODE_SNIFFER) $(CODE_SNIFFER_FIX)
63-
php $(CODE_SNIFFER_FIX) || true
64-
php $(CODE_SNIFFER)
61+
cs: ## Fixes CS
62+
cs: php_cs_fixer
63+
64+
.PHONY: cs_lint
65+
cs_lint: ## Checks CS
66+
cs_lint: composer_normalize_lint php_cs_fixer_lint
67+
68+
.PHONY: php_cs_fixer
69+
php_cs_fixer: $(PHP_CS_FIXER_BIN)
70+
$(PHP_CS_FIXER)
6571

66-
.PHONY: cs-check
67-
cs-check: ## Checks CS
68-
cs-check: $(CODE_SNIFFER)
69-
php $(CODE_SNIFFER)
72+
.PHONY: php_cs_fixer_lint
73+
php_cs_fixer_lint: $(PHP_CS_FIXER_BIN)
74+
$(PHP_CS_FIXER) --dry-run
75+
76+
.PHONY: composer_normalize
77+
composer_normalize: composer.json vendor
78+
composer normalize
79+
80+
.PHONY: composer_normalize_lint
81+
composer_normalize_lint: composer.json vendor
82+
composer normalize --dry-run
7083

7184
.PHONY: phpstan
7285
phpstan: ## Runs PHPStan
@@ -132,8 +145,8 @@ infection: $(COVERAGE_XML) vendor
132145
.PHONY: blackfire
133146
blackfire: ## Runs Blackfire profiling
134147
blackfire: $(PHP_SCOPER_BIN) vendor
135-
@echo By https://blackfire.io
136-
@echo This might take a while (~2min)
148+
@echo "By https://blackfire.io"
149+
@echo "This might take a while (~2min)"
137150
$(BLACKFIRE) run php $(PHP_SCOPER_BIN) add-prefix --output-dir=build/php-scoper --force --quiet
138151

139152
.PHONY: e2e
@@ -509,20 +522,20 @@ vendor-bin/covers-validator/vendor: vendor-bin/covers-validator/composer.lock $(
509522
vendor-bin/covers-validator/composer.lock: vendor-bin/covers-validator/composer.json
510523
@echo covers-validator composer.lock is not up to date
511524

525+
$(PHP_CS_FIXER_BIN): vendor-bin/php-cs-fixer/vendor
526+
vendor-bin/php-cs-fixer/vendor: vendor-bin/php-cs-fixer/composer.lock $(COMPOSER_BIN_PLUGIN_VENDOR)
527+
composer bin php-cs-fixer install
528+
touch -c $@
529+
vendor-bin/php-cs-fixer/composer.lock: vendor-bin/php-cs-fixer/composer.json
530+
@echo php-cs-fixer composer.lock is not up to date
531+
512532
$(PHPSTAN_BIN): vendor-bin/phpstan/vendor
513533
vendor-bin/phpstan/vendor: vendor-bin/phpstan/composer.lock $(COMPOSER_BIN_PLUGIN_VENDOR)
514534
composer bin phpstan install
515535
touch -c $@
516536
vendor-bin/phpstan/composer.lock: vendor-bin/phpstan/composer.json
517537
@echo phpstan composer.lock is not up to date
518538

519-
vendor-bin/code-sniffer/vendor: vendor-bin/code-sniffer/composer.lock $(COMPOSER_BIN_PLUGIN_VENDOR)
520-
composer bin code-sniffer install
521-
touch -c $@
522-
523-
vendor-bin/code-sniffer/composer.lock: vendor-bin/code-sniffer/composer.json
524-
@echo code-sniffer composer.lock is not up to date
525-
526539
$(PHP_SCOPER_BIN): $(BOX) bin/php-scoper $(SRC_FILES) vendor-hotfix vendor scoper.inc.php box.json.dist
527540
$(BOX) compile
528541
touch -c $@
@@ -531,14 +544,6 @@ $(COVERAGE_XML): $(PHPUNIT_BIN) $(SRC_FILES)
531544
$(MAKE) phpunit_coverage_infection
532545
touch -c "$@"
533546

534-
$(CODE_SNIFFER): vendor-bin/code-sniffer/vendor
535-
composer bin code-sniffer install
536-
touch -c $@
537-
538-
$(CODE_SNIFFER_FIX): vendor-bin/code-sniffer/vendor
539-
composer bin code-sniffer install
540-
touch -c $@
541-
542547
fixtures/set005/vendor: fixtures/set005/composer.lock
543548
composer --working-dir=fixtures/set005 install
544549
touch -c $@

bin/check-composer-root-version.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
preg_match(
3636
'/COMPOSER_ROOT_VERSION=\'(?<version>.*?)\'/',
3737
file_get_contents(__DIR__.'/../.composer-root-version'),
38-
$matches
38+
$matches,
3939
);
4040

4141
$currentRootVersion = $matches['version'];
@@ -46,8 +46,8 @@
4646
sprintf(
4747
'Expected the COMPOSER_ROOT_VERSION value to be "%s" but got "%s" instead.'.PHP_EOL,
4848
$expectedComposerRootVersion,
49-
$currentRootVersion
50-
)
49+
$currentRootVersion,
50+
),
5151
);
5252

5353
exit(1);

bin/dump-composer-root-version.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
__DIR__.'/../.composer-root-version',
3838
sprintf(
3939
<<<'BASH'
40-
#!/usr/bin/env bash
41-
42-
export COMPOSER_ROOT_VERSION='%s'
43-
44-
BASH,
40+
#!/usr/bin/env bash
41+
42+
export COMPOSER_ROOT_VERSION='%s'
43+
44+
BASH,
4545
$composerRootVersion,
4646
),
4747
);
@@ -52,7 +52,7 @@
5252
'/COMPOSER_ROOT_VERSION: \'.*?\'/',
5353
sprintf(
5454
'COMPOSER_ROOT_VERSION: \'%s\'',
55-
$composerRootVersion
55+
$composerRootVersion,
5656
),
5757
file_get_contents($scrutinizerPath),
5858
),

bin/php-scoper

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ set_error_handler(
3131
if (error_reporting() & $code) {
3232
throw new ErrorException($message, 0, $code, $file, $line);
3333
}
34-
}
34+
},
3535
);
3636

3737
$findAutoload = static function () {

bin/root-version.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ function request_tags(): string
3434

3535
$headerOption = false === $gitHubToken || '' === $gitHubToken
3636
? ''
37-
: "-H \"Authorization: token $gitHubToken\""
38-
;
37+
: "-H \"Authorization: token {$gitHubToken}\"";
3938

4039
$command = <<<BASH
41-
curl -s $headerOption https://api.github.com/repos/humbug/php-scoper/tags?per_page=1
42-
BASH;
40+
curl -s {$headerOption} https://api.github.com/repos/humbug/php-scoper/tags?per_page=1
41+
BASH;
4342

4443
echo 'cURL command:'.PHP_EOL;
4544
echo '$ '.$command;
@@ -67,7 +66,7 @@ function parse_tag(string $responseContent): string
6766
throw new RuntimeException(
6867
sprintf(
6968
'No tag name could be found in: %s',
70-
$responseContent
69+
$responseContent,
7170
),
7271
100,
7372
);
@@ -79,7 +78,7 @@ function parse_tag(string $responseContent): string
7978
throw new RuntimeException(
8079
sprintf(
8180
'No tag name could be found in: %s',
82-
$responseContent
81+
$responseContent,
8382
),
8483
100,
8584
);
@@ -89,7 +88,7 @@ function parse_tag(string $responseContent): string
8988
throw new RuntimeException(
9089
sprintf(
9190
'No tag name could be found in: %s',
92-
$responseContent
91+
$responseContent,
9392
),
9493
100,
9594
);

composer.json

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
"email": "padraic.brady@gmail.com"
1717
}
1818
],
19-
20-
"minimum-stability": "dev",
21-
"prefer-stable": true,
2219
"require": {
2320
"php": "^8.1",
2421
"composer/package-versions-deprecated": "^1.8",
@@ -34,42 +31,46 @@
3431
},
3532
"require-dev": {
3633
"bamarni/composer-bin-plugin": "^1.1",
34+
"ergebnis/composer-normalize": "^2.28",
3735
"humbug/box": "^4.0",
3836
"phpspec/prophecy-phpunit": "^2.0",
3937
"phpunit/phpunit": "^9.0"
4038
},
4139
"replace": {
4240
"symfony/polyfill-php73": "*"
4341
},
44-
45-
"bin": ["bin/php-scoper"],
42+
"minimum-stability": "dev",
43+
"prefer-stable": true,
4644
"autoload": {
47-
"files": [
48-
"src/functions.php"
49-
],
5045
"psr-4": {
5146
"Humbug\\PhpScoper\\": "src/"
52-
}
47+
},
48+
"files": [
49+
"src/functions.php"
50+
]
5351
},
5452
"autoload-dev": {
55-
"files": [
56-
"tests/functions.php"
57-
],
5853
"psr-4": {
5954
"Humbug\\PhpScoper\\": "tests/"
60-
}
55+
},
56+
"files": [
57+
"tests/functions.php"
58+
]
6159
},
62-
60+
"bin": [
61+
"bin/php-scoper"
62+
],
6363
"config": {
64+
"allow-plugins": {
65+
"bamarni/composer-bin-plugin": true,
66+
"composer/package-versions-deprecated": true,
67+
"ergebnis/composer-normalize": true
68+
},
6469
"bin-dir": "bin",
65-
"sort-packages": true,
6670
"platform": {
6771
"php": "8.1.0"
6872
},
69-
"allow-plugins": {
70-
"bamarni/composer-bin-plugin": true,
71-
"composer/package-versions-deprecated": true
72-
}
73+
"sort-packages": true
7374
},
7475
"extra": {
7576
"bamarni-bin": {

0 commit comments

Comments
 (0)