Skip to content

Commit

Permalink
Merge branch 'master' into fix_PhpdocScalarFixer
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Feb 1, 2024
2 parents 20c8e64 + 21f5b42 commit 22485fc
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/issues_and_pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
days-before-pr-close: "${{ env.DAYS_BEFORE_PR_CLOSE }}"
days-before-pr-stale: "${{ env.DAYS_BEFORE_PR_STALE }}"
exempt-all-milestones: true
exempt-issue-labels: "topic/core"
exempt-pr-labels: "topic/core"
labels-to-add-when-unstale: "status/to verify"
repo-token: "${{ secrets.GITHUB_TOKEN }}"
stale-issue-label: "status/stale"
Expand Down
12 changes: 5 additions & 7 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,11 @@ To visualize all the rules that belong to a ruleset:
Caching
-------

The caching mechanism is enabled by default. This will speed up further runs by
fixing only files that were modified since the last run. The tool will fix all
files if the tool version has changed or the list of rules has changed.
The cache is supported only when the tool was downloaded as a phar file or
installed via Composer. The cache is written to the drive progressively, so do
not be afraid of interruption - rerun the command and start where you left.
The cache mechanism also supports executing the command in parallel.
The caching mechanism is enabled by default. This will speed up further runs by fixing only files that were modified
since the last run. The tool will fix all files if the tool version has changed or the list of rules has changed.
The cache is supported only when the tool was downloaded as a PHAR file, executed within pre-built Docker image
or installed via Composer. The cache is written to the drive progressively, so do not be afraid of interruption -
rerun the command and start where you left. The cache mechanism also supports executing the command in parallel.

Cache can be disabled via ``--using-cache`` option or config file:

Expand Down
9 changes: 8 additions & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public function getUsingCache(): bool
}
}

$this->usingCache = $this->usingCache && ($this->toolInfo->isInstalledAsPhar() || $this->toolInfo->isInstalledByComposer());
$this->usingCache = $this->usingCache && $this->isCachingAllowedForRuntime();

return $this->usingCache;
}
Expand Down Expand Up @@ -949,4 +949,11 @@ private static function separatedContextLessInclude(string $path): ConfigInterfa

return $config;
}

private function isCachingAllowedForRuntime(): bool
{
return $this->toolInfo->isInstalledAsPhar()
|| $this->toolInfo->isInstalledByComposer()
|| $this->toolInfo->isRunInsideDocker();
}
}
9 changes: 9 additions & 0 deletions src/ToolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public function isInstalledByComposer(): bool
return $this->isInstalledByComposer;
}

/**
* Determines if the tool is run inside our pre-built Docker image.
* The `/fixer/` path comes from our Dockerfile, tool is installed there and added to global PATH via symlinked binary.
*/
public function isRunInsideDocker(): bool
{
return is_file('/.dockerenv') && str_starts_with(__FILE__, '/fixer/');
}

public function getPharDownloadUri(string $version): string
{
return sprintf(
Expand Down
2 changes: 2 additions & 0 deletions src/ToolInfoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ public function isInstalledAsPhar(): bool;

public function isInstalledByComposer(): bool;

public function isRunInsideDocker(): bool;

public function getPharDownloadUri(string $version): string;
}
5 changes: 5 additions & 0 deletions tests/Console/Command/SelfUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ public function isInstalledByComposer(): bool
throw new \LogicException('Not implemented.');
}

public function isRunInsideDocker(): bool
{
return false;
}

public function getPharDownloadUri(string $version): string
{
return sprintf('%s/%s.phar', $this->directory->url(), $version);
Expand Down
99 changes: 91 additions & 8 deletions tests/Console/ConfigurationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,84 @@ public function testResolveUsingCacheWithNegativeConfigAndNoOption(): void
self::assertFalse($resolver->getUsingCache());
}

/**
* @dataProvider provideResolveUsingCacheForRuntimesCases
*/
public function testResolveUsingCacheForRuntimes(bool $cacheAllowed, bool $installedWithComposer, bool $asPhar, bool $inDocker): void
{
$config = new Config();
$config->setUsingCache(true);

$resolver = $this->createConfigurationResolver(
[],
$config,
'',
new class($installedWithComposer, $asPhar, $inDocker) implements ToolInfoInterface {
private bool $installedWithComposer;
private bool $asPhar;
private bool $inDocker;

public function __construct(bool $installedWithComposer, bool $asPhar, bool $inDocker)
{
$this->installedWithComposer = $installedWithComposer;
$this->asPhar = $asPhar;
$this->inDocker = $inDocker;
}

public function getComposerInstallationDetails(): array
{
throw new \BadMethodCallException();
}

public function getComposerVersion(): string
{
throw new \BadMethodCallException();
}

public function getVersion(): string
{
throw new \BadMethodCallException();
}

public function isInstalledAsPhar(): bool
{
return $this->asPhar;
}

public function isInstalledByComposer(): bool
{
return $this->installedWithComposer;
}

public function isRunInsideDocker(): bool
{
return $this->inDocker;
}

public function getPharDownloadUri(string $version): string
{
throw new \BadMethodCallException();
}
}
);

self::assertSame($cacheAllowed, $resolver->getUsingCache());
}

/**
* @return iterable<array{0: bool, 1: bool, 2: bool, 3: bool}>
*/
public static function provideResolveUsingCacheForRuntimesCases(): iterable
{
yield 'none of the allowed runtimes' => [false, false, false, false];

yield 'composer installation' => [true, true, false, false];

yield 'PHAR distribution' => [true, false, true, false];

yield 'Docker runtime' => [true, false, false, true];
}

public function testResolveCacheFileWithoutConfigAndOption(): void
{
$config = new Config();
Expand Down Expand Up @@ -1303,17 +1381,17 @@ private static function getFixtureDir(): string
/**
* @param array<string, mixed> $options
*/
private function createConfigurationResolver(array $options, Config $config = null, string $cwdPath = ''): ConfigurationResolver
{
if (null === $config) {
$config = new Config();
}

private function createConfigurationResolver(
array $options,
Config $config = null,
string $cwdPath = '',
ToolInfoInterface $toolInfo = null
): ConfigurationResolver {
return new ConfigurationResolver(
$config,
$config ?? new Config(),
$options,
$cwdPath,
$this->createToolInfoDouble()
$toolInfo ?? $this->createToolInfoDouble()
);
}

Expand Down Expand Up @@ -1379,6 +1457,11 @@ public function isInstalledByComposer(): bool
throw new \BadMethodCallException();
}

public function isRunInsideDocker(): bool
{
return false;
}

public function getPharDownloadUri(string $version): string
{
throw new \BadMethodCallException();
Expand Down
5 changes: 5 additions & 0 deletions tests/Console/WarningsDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function isInstalledByComposer(): bool
return $this->isInstalledByComposer;
}

public function isRunInsideDocker(): bool
{
return false;
}

public function getPharDownloadUri(string $version): string
{
throw new \LogicException('Not implemented.');
Expand Down

0 comments on commit 22485fc

Please sign in to comment.