Skip to content

Commit 6d567e6

Browse files
authored
[1.x] Makes Pint 40x faster (#376)
* Adds `--parallel` * Bumps dependencies * sends build * Puts in place overrides * Uses `setUnsupportedPhpVersionAllowed` * fix * Fixes types * adds `(Experimental)` * Fixes CI * note * chore: ignores overrides on export * buillds * fix
1 parent 6f113c1 commit 6d567e6

File tree

10 files changed

+436
-274
lines changed

10 files changed

+436
-274
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: true
1818
matrix:
19-
os: [ubuntu-22.04, windows-2019]
19+
os: [ubuntu-22.04, windows-2022]
2020
php: [8.2, 8.3, 8.4]
2121

2222
name: PHP ${{ matrix.php }} - ${{ matrix.os }}
@@ -52,6 +52,9 @@ jobs:
5252
- name: Execute lint tests with Laravel preset
5353
run: ./pint --test
5454

55+
- name: Execute lint tests in parallel with Laravel preset
56+
run: ./pint --parallel --test
57+
5558
- name: Execute static analysis
5659
run: vendor/bin/phpstan
5760
if: matrix.php == '8.4'

app/Actions/FixCode.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use App\Factories\ConfigurationResolverFactory;
66
use LaravelZero\Framework\Exceptions\ConsoleException;
7+
use PhpCsFixer\Console\ConfigurationResolver;
78
use PhpCsFixer\Runner\Runner;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
811

912
class FixCode
1013
{
@@ -45,8 +48,10 @@ public function execute()
4548
$this->progress->subscribe();
4649
}
4750

51+
$method = $this->input->getOption('parallel') ? 'fixParallel' : 'fixSequential';
52+
4853
/** @var array<string, array{appliedFixers: array<int, string>, diff: string}> $changes */
49-
$changes = (new Runner(
54+
$changes = (fn () => $this->{$method}())->call(new Runner(
5055
$resolver->getFinder(),
5156
$resolver->getFixers(),
5257
$resolver->getDiffer(),
@@ -56,9 +61,34 @@ public function execute()
5661
$resolver->isDryRun(),
5762
$resolver->getCacheManager(),
5863
$resolver->getDirectory(),
59-
$resolver->shouldStopOnViolation()
60-
))->fix();
64+
$resolver->shouldStopOnViolation(),
65+
$resolver->getParallelConfig(),
66+
$this->getInput($resolver),
67+
));
6168

6269
return tap([$totalFiles, $changes], fn () => $this->progress->unsubscribe());
6370
}
71+
72+
/**
73+
* Gets the input for the PHP CS Fixer Runner.
74+
*/
75+
private function getInput(ConfigurationResolver $resolver): InputInterface
76+
{
77+
// @phpstan-ignore-next-line
78+
$definition = (fn () => $this->definition)->call($this->input);
79+
80+
$definition->addOptions([
81+
new InputOption('stop-on-violation', null, InputOption::VALUE_REQUIRED, ''),
82+
new InputOption('allow-risky', null, InputOption::VALUE_REQUIRED, ''),
83+
new InputOption('rules', null, InputOption::VALUE_REQUIRED, ''),
84+
new InputOption('using-cache', null, InputOption::VALUE_REQUIRED, ''),
85+
]);
86+
87+
$this->input->setOption('stop-on-violation', $resolver->shouldStopOnViolation());
88+
$this->input->setOption('allow-risky', $resolver->getRiskyAllowed() ? 'yes' : 'no');
89+
$this->input->setOption('rules', json_encode($resolver->getRules()));
90+
$this->input->setOption('using-cache', $resolver->getUsingCache() ? 'yes' : 'no');
91+
92+
return $this->input;
93+
}
6494
}

app/Commands/DefaultCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ protected function configure()
4747
new InputOption('output-to-file', '', InputOption::VALUE_REQUIRED, 'Output the test results to a file at this path'),
4848
new InputOption('output-format', '', InputOption::VALUE_REQUIRED, 'The format that should be used when outputting the test results to a file'),
4949
new InputOption('cache-file', '', InputArgument::OPTIONAL, 'The path to the cache file'),
50-
]
50+
new InputOption('parallel', '', InputOption::VALUE_NONE, 'Runs the linter in parallel (Experimental)'),
51+
],
5152
);
5253
}
5354

app/Factories/ConfigurationFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ class ConfigurationFactory
4242
*/
4343
public static function preset($rules)
4444
{
45-
return (new Config)
45+
return (new Config) // @phpstan-ignore-line
4646
->setParallelConfig(ParallelConfigFactory::detect())
4747
->setFinder(self::finder())
4848
->setRules(array_merge($rules, resolve(ConfigurationJsonRepository::class)->rules()))
4949
->setRiskyAllowed(true)
50-
->setUsingCache(true);
50+
->setUsingCache(true)
51+
->setUnsupportedPhpVersionAllowed(true);
5152
}
5253

5354
/**

box.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"app",
55
"bootstrap",
66
"config",
7+
"overrides",
78
"resources",
89
"vendor"
910
],

builds/pint

382 KB
Binary file not shown.

composer.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"ext-xml": "*"
2424
},
2525
"require-dev": {
26-
"friendsofphp/php-cs-fixer": "^3.75.0",
27-
"illuminate/view": "^11.44.7",
28-
"larastan/larastan": "^3.4.0",
29-
"laravel-zero/framework": "^11.36.1",
26+
"friendsofphp/php-cs-fixer": "^3.76.0",
27+
"illuminate/view": "^11.45.1",
28+
"larastan/larastan": "^3.5.0",
29+
"laravel-zero/framework": "^11.45.0",
3030
"mockery/mockery": "^1.6.12",
3131
"nunomaduro/termwind": "^2.3.1",
3232
"pestphp/pest": "^2.36.0"
@@ -36,7 +36,10 @@
3636
"App\\": "app/",
3737
"Database\\Factories\\": "database/factories/",
3838
"Database\\Seeders\\": "database/seeders/"
39-
}
39+
},
40+
"files": [
41+
"overrides/Runner/Parallel/ProcessFactory.php"
42+
]
4043
},
4144
"autoload-dev": {
4245
"psr-4": {

0 commit comments

Comments
 (0)