Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
php-version: ${{ fromJson(needs.setup.outputs.php-versions) }}
tool: ${{ fromJson(needs.setup.outputs.tools) }}
fail-fast: false
name: ${{ matrix.php-version }} - ${{ matrix.tool }}
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
Expand Down
11 changes: 9 additions & 2 deletions src/Command/CodesnifferCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ protected function getProcess(InputInterface $input): Process
{
if ($this->isGitHubFormat($input)) {
return Process::fromShellCommandline(
$this->withVendorBinPath('phpcs') . ' -q --report=checkstyle | cs2pr',
\sprintf(
'%s -q --parallel=%s --report=checkstyle | cs2pr',
$this->withVendorBinPath('phpcs'),
$this->configuration->getThreads(),
),
timeout: null,
);
}

return new Process(
[$this->withVendorBinPath('phpcs')],
[
$this->withVendorBinPath('phpcs'),
'--parallel=' . $this->configuration->getThreads(),
],
timeout: null,
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Command/PsalmCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ final class PsalmCommand extends DevToolsCommand

protected function getProcess(InputInterface $input): Process
{
$command = [$this->withVendorBinPath('psalm')];
$command = [
$this->withVendorBinPath('psalm'),
'--threads=' . $this->configuration->getThreads(),
];

if ($this->isGitHubFormat($input)) {
$command[] = '--output-format=github';
Expand Down
21 changes: 12 additions & 9 deletions src/Command/RoaveInfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ final class RoaveInfectionCommand extends DevToolsCommand

protected function getProcess(InputInterface $input): Process
{
return new Process(
[
$this->withVendorBinPath('roave-infection-static-analysis-plugin'),
'--only-covered',
'--show-mutations',
],
env: ['XDEBUG_MODE' => 'coverage'],
timeout: null,
);
$command = [
$this->withVendorBinPath('roave-infection-static-analysis-plugin'),
'--threads=' . $this->configuration->getThreads(),
'--only-covered',
'--show-mutations',
];

if ($this->isGitHubFormat($input)) {
$command[] = '--logger-github';
}

return new Process($command, env: ['XDEBUG_MODE' => 'coverage'], timeout: null);
}

public static function isAvailable(Configuration $configuration): bool
Expand Down
80 changes: 51 additions & 29 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Composer\Semver\Semver;
use MyOnlineStore\DevTools\Command\DevToolsCommand;
use Symfony\Component\Process\Process;

final class Configuration
{
Expand All @@ -20,6 +21,7 @@ final class Configuration
private ?array $phpVersions = null;

private string $rootDir;
private ?string $threads = null;

public function __construct()
{
Expand All @@ -40,6 +42,55 @@ public function __construct()
throw new \RuntimeException('Unable to determine project root');
}

/**
* @return array<string, class-string<DevToolsCommand>>
*/
public function getEnabledTools(): array
{
if (null === $this->enabledTools) {
$this->enabledTools = $this->gatherEnabledTools();
}

return $this->enabledTools;
}

/**
* @return list<string>
*/
public function getPhpVersions(): array
{
if (null === $this->phpVersions) {
$this->phpVersions = $this->gatherPhpVersions();
}

return $this->phpVersions;
}

public function getRootDir(): string
{
return $this->rootDir;
}

public function getThreads(): string
{
if (null === $this->threads) {
$this->threads = $this->determineThreads();
}

return $this->threads;
}

private function determineThreads(): string
{
return \trim(
match (\php_uname('s')) {
'Linux' => Process::fromShellCommandline('nproc')->mustRun()->getOutput(),
'Darwin' => Process::fromShellCommandline('sysctl -n hw.logicalcpu')->mustRun()->getOutput(),
default => '2',
}
);
}

/**
* @return list<string>
*/
Expand Down Expand Up @@ -111,33 +162,4 @@ private function gatherEnabledTools(): array

return $enabledTools;
}

/**
* @return array<string, class-string<DevToolsCommand>>
*/
public function getEnabledTools(): array
{
if (null === $this->enabledTools) {
$this->enabledTools = $this->gatherEnabledTools();
}

return $this->enabledTools;
}

/**
* @return list<string>
*/
public function getPhpVersions(): array
{
if (null === $this->phpVersions) {
$this->phpVersions = $this->gatherPhpVersions();
}

return $this->phpVersions;
}

public function getRootDir(): string
{
return $this->rootDir;
}
}