Skip to content

Commit 3541eba

Browse files
chore: Add --threads argument where possible (#8)
1 parent eac50e5 commit 3541eba

File tree

5 files changed

+77
-41
lines changed

5 files changed

+77
-41
lines changed

.github/workflows/test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
php-version: ${{ fromJson(needs.setup.outputs.php-versions) }}
2929
tool: ${{ fromJson(needs.setup.outputs.tools) }}
3030
fail-fast: false
31+
name: ${{ matrix.php-version }} - ${{ matrix.tool }}
3132
steps:
3233
- uses: actions/checkout@v3
3334
- uses: shivammathur/setup-php@v2

src/Command/CodesnifferCommand.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ protected function getProcess(InputInterface $input): Process
1919
{
2020
if ($this->isGitHubFormat($input)) {
2121
return Process::fromShellCommandline(
22-
$this->withVendorBinPath('phpcs') . ' -q --report=checkstyle | cs2pr',
22+
\sprintf(
23+
'%s -q --parallel=%s --report=checkstyle | cs2pr',
24+
$this->withVendorBinPath('phpcs'),
25+
$this->configuration->getThreads(),
26+
),
2327
timeout: null,
2428
);
2529
}
2630

2731
return new Process(
28-
[$this->withVendorBinPath('phpcs')],
32+
[
33+
$this->withVendorBinPath('phpcs'),
34+
'--parallel=' . $this->configuration->getThreads(),
35+
],
2936
timeout: null,
3037
);
3138
}

src/Command/PsalmCommand.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ final class PsalmCommand extends DevToolsCommand
1717

1818
protected function getProcess(InputInterface $input): Process
1919
{
20-
$command = [$this->withVendorBinPath('psalm')];
20+
$command = [
21+
$this->withVendorBinPath('psalm'),
22+
'--threads=' . $this->configuration->getThreads(),
23+
];
2124

2225
if ($this->isGitHubFormat($input)) {
2326
$command[] = '--output-format=github';

src/Command/RoaveInfectionCommand.php

+12-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ final class RoaveInfectionCommand extends DevToolsCommand
1717

1818
protected function getProcess(InputInterface $input): Process
1919
{
20-
return new Process(
21-
[
22-
$this->withVendorBinPath('roave-infection-static-analysis-plugin'),
23-
'--only-covered',
24-
'--show-mutations',
25-
],
26-
env: ['XDEBUG_MODE' => 'coverage'],
27-
timeout: null,
28-
);
20+
$command = [
21+
$this->withVendorBinPath('roave-infection-static-analysis-plugin'),
22+
'--threads=' . $this->configuration->getThreads(),
23+
'--only-covered',
24+
'--show-mutations',
25+
];
26+
27+
if ($this->isGitHubFormat($input)) {
28+
$command[] = '--logger-github';
29+
}
30+
31+
return new Process($command, env: ['XDEBUG_MODE' => 'coverage'], timeout: null);
2932
}
3033

3134
public static function isAvailable(Configuration $configuration): bool

src/Configuration.php

+51-29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Composer\Semver\Semver;
77
use MyOnlineStore\DevTools\Command\DevToolsCommand;
8+
use Symfony\Component\Process\Process;
89

910
final class Configuration
1011
{
@@ -20,6 +21,7 @@ final class Configuration
2021
private ?array $phpVersions = null;
2122

2223
private string $rootDir;
24+
private ?string $threads = null;
2325

2426
public function __construct()
2527
{
@@ -40,6 +42,55 @@ public function __construct()
4042
throw new \RuntimeException('Unable to determine project root');
4143
}
4244

45+
/**
46+
* @return array<string, class-string<DevToolsCommand>>
47+
*/
48+
public function getEnabledTools(): array
49+
{
50+
if (null === $this->enabledTools) {
51+
$this->enabledTools = $this->gatherEnabledTools();
52+
}
53+
54+
return $this->enabledTools;
55+
}
56+
57+
/**
58+
* @return list<string>
59+
*/
60+
public function getPhpVersions(): array
61+
{
62+
if (null === $this->phpVersions) {
63+
$this->phpVersions = $this->gatherPhpVersions();
64+
}
65+
66+
return $this->phpVersions;
67+
}
68+
69+
public function getRootDir(): string
70+
{
71+
return $this->rootDir;
72+
}
73+
74+
public function getThreads(): string
75+
{
76+
if (null === $this->threads) {
77+
$this->threads = $this->determineThreads();
78+
}
79+
80+
return $this->threads;
81+
}
82+
83+
private function determineThreads(): string
84+
{
85+
return \trim(
86+
match (\php_uname('s')) {
87+
'Linux' => Process::fromShellCommandline('nproc')->mustRun()->getOutput(),
88+
'Darwin' => Process::fromShellCommandline('sysctl -n hw.logicalcpu')->mustRun()->getOutput(),
89+
default => '2',
90+
}
91+
);
92+
}
93+
4394
/**
4495
* @return list<string>
4596
*/
@@ -111,33 +162,4 @@ private function gatherEnabledTools(): array
111162

112163
return $enabledTools;
113164
}
114-
115-
/**
116-
* @return array<string, class-string<DevToolsCommand>>
117-
*/
118-
public function getEnabledTools(): array
119-
{
120-
if (null === $this->enabledTools) {
121-
$this->enabledTools = $this->gatherEnabledTools();
122-
}
123-
124-
return $this->enabledTools;
125-
}
126-
127-
/**
128-
* @return list<string>
129-
*/
130-
public function getPhpVersions(): array
131-
{
132-
if (null === $this->phpVersions) {
133-
$this->phpVersions = $this->gatherPhpVersions();
134-
}
135-
136-
return $this->phpVersions;
137-
}
138-
139-
public function getRootDir(): string
140-
{
141-
return $this->rootDir;
142-
}
143165
}

0 commit comments

Comments
 (0)