Skip to content

Commit

Permalink
Add php-cs-fixer CI job
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 17, 2023
1 parent 21ead39 commit e395f04
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,35 @@ jobs:
run: "test_old/run-php-src.sh 8.3.0RC2"
phpstan:
runs-on: "ubuntu-latest"
name: "PHP ${{ matrix.php-version }} PHPStan"
strategy:
matrix:
php-version:
- "8.2"
name: "PHPStan"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
php-version: "8.2"
tools: composer:v2
- name: "Install dependencies"
run: |
run: |
cd tools && composer install
- name: "PHPStan"
run: "php tools/vendor/bin/phpstan"
php-cs-fixer:
runs-on: "ubuntu-latest"
name: "PHP-CS-Fixer"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.2"
tools: composer:v2
- name: "Install dependencies"
run: |
cd tools && composer install
- name: "php-cs-fixer"
run: "php tools/vendor/bin/php-cs-fixer fix"
5 changes: 5 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
'declare_strict_types' => true,
// Keep argument formatting for now.
'method_argument_space' => ['on_multiline' => 'ignore'],
'binary_operator_spaces' => [
'default' => 'at_least_single_space',
// Work around https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7303.
'operators' => ['=' => null],
],
])
->setFinder($finder)
;
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: phpstan php-cs-fixer

tools/vendor:
composer install -d tools

phpstan: tools/vendor
tools/vendor/bin/phpstan

php-cs-fixer: tools/vendor
tools/vendor/bin/php-cs-fixer fix
14 changes: 7 additions & 7 deletions lib/PhpParser/Internal/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ private function calculateTrace(array $old, array $new): array {
for ($d = 0; $d <= $max; $d++) {
$trace[] = $v;
for ($k = -$d; $k <= $d; $k += 2) {
if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) {
$x = $v[$k+1];
if ($k === -$d || ($k !== $d && $v[$k - 1] < $v[$k + 1])) {
$x = $v[$k + 1];
} else {
$x = $v[$k-1] + 1;
$x = $v[$k - 1] + 1;
}

$y = $x - $k;
Expand Down Expand Up @@ -103,7 +103,7 @@ private function extractDiff(array $trace, int $x, int $y, array $old, array $ne
$v = $trace[$d];
$k = $x - $y;

if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) {
if ($k === -$d || ($k !== $d && $v[$k - 1] < $v[$k + 1])) {
$prevK = $k + 1;
} else {
$prevK = $k - 1;
Expand All @@ -113,7 +113,7 @@ private function extractDiff(array $trace, int $x, int $y, array $old, array $ne
$prevY = $prevX - $prevK;

while ($x > $prevX && $y > $prevY) {
$result[] = new DiffElem(DiffElem::TYPE_KEEP, $old[$x-1], $new[$y-1]);
$result[] = new DiffElem(DiffElem::TYPE_KEEP, $old[$x - 1], $new[$y - 1]);
$x--;
$y--;
}
Expand All @@ -123,12 +123,12 @@ private function extractDiff(array $trace, int $x, int $y, array $old, array $ne
}

while ($x > $prevX) {
$result[] = new DiffElem(DiffElem::TYPE_REMOVE, $old[$x-1], null);
$result[] = new DiffElem(DiffElem::TYPE_REMOVE, $old[$x - 1], null);
$x--;
}

while ($y > $prevY) {
$result[] = new DiffElem(DiffElem::TYPE_ADD, null, $new[$y-1]);
$result[] = new DiffElem(DiffElem::TYPE_ADD, null, $new[$y - 1]);
$y--;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/PhpParser/Node/Scalar/String_.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ private static function codePointToUtf8(int $num): string {
return chr($num);
}
if ($num <= 0x7FF) {
return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80);
return chr(($num >> 6) + 0xC0) . chr(($num & 0x3F) + 0x80);
}
if ($num <= 0xFFFF) {
return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80);
return chr(($num >> 12) + 0xE0) . chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80);
}
if ($num <= 0x1FFFFF) {
return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80)
. chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80);
return chr(($num >> 18) + 0xF0) . chr((($num >> 12) & 0x3F) + 0x80)
. chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80);
}
throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/PrettyPrinter/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function pScalar_InterpolatedString(Scalar\InterpolatedString $node):
}

protected function pScalar_Int(Scalar\Int_ $node): string {
if ($node->value === -\PHP_INT_MAX-1) {
if ($node->value === -\PHP_INT_MAX - 1) {
// PHP_INT_MIN cannot be represented as a literal,
// because the sign is not part of the literal
return '(-' . \PHP_INT_MAX . '-1)';
Expand Down

0 comments on commit e395f04

Please sign in to comment.