Skip to content

Commit

Permalink
Rename fixerTmpDir to pro.tmpDir and allow to override it
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 14, 2023
1 parent 4a95206 commit 7c4ef6b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ parameters:
polluteScopeWithAlwaysIterableForeach: true
propertyAlwaysWrittenTags: []
propertyAlwaysReadTags: []
fixerTmpDir: %pro.tmpDir% #unused
additionalConstructors: []
treatPhpDocTypesAsCertain: true
usePathConstantsAsConstantString: false
Expand Down Expand Up @@ -233,9 +234,11 @@ parameters:
editorUrl: null
editorUrlTitle: null
errorFormat: null
sysGetTempDir: ::sys_get_temp_dir()
pro:
dnsServers:
- '1.1.1.2'
tmpDir: %sysGetTempDir%/phpstan-fixer
__validate: true

extensions:
Expand Down Expand Up @@ -520,7 +523,7 @@ services:
arguments:
analysedPaths: %analysedPaths%
currentWorkingDirectory: %currentWorkingDirectory%
fixerTmpDir: %fixerTmpDir%
proTmpDir: %pro.tmpDir%
dnsServers: %pro.dnsServers%

-
Expand Down
4 changes: 3 additions & 1 deletion conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,16 @@ parametersSchema:
mixinExcludeClasses: listOf(string())
scanFiles: listOf(string())
scanDirectories: listOf(string())
fixerTmpDir: string()
fixerTmpDir: string() #unused
editorUrl: schema(string(), nullable())
editorUrlTitle: schema(string(), nullable())
errorFormat: schema(string(), nullable())
pro: structure([
dnsServers: schema(listOf(string()), min(1)),
tmpDir: string()
])
env: arrayOf(string(), string())
sysGetTempDir: string()

# irrelevant Nette parameters
debugMode: bool()
Expand Down
18 changes: 9 additions & 9 deletions src/Command/FixerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
private IgnoredErrorHelper $ignoredErrorHelper,
private array $analysedPaths,
private string $currentWorkingDirectory,
private string $fixerTmpDir,
private string $proTmpDir,
private array $dnsServers,
)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ public function run(
return;
}
$output->writeln(sprintf('<fg=red>PHPStan Pro process exited with code %d.</>', $exitCode));
@unlink($this->fixerTmpDir . '/phar-info.json');
@unlink($this->proTmpDir . '/phar-info.json');
});

$loop->run();
Expand All @@ -197,13 +197,13 @@ public function run(
*/
private function getFixerProcess(OutputInterface $output, int $serverPort): Process
{
if (!@mkdir($this->fixerTmpDir, 0777) && !is_dir($this->fixerTmpDir)) {
$output->writeln(sprintf('Cannot create a temp directory %s', $this->fixerTmpDir));
if (!@mkdir($this->proTmpDir, 0777) && !is_dir($this->proTmpDir)) {
$output->writeln(sprintf('Cannot create a temp directory %s', $this->proTmpDir));
throw new FixerProcessException();
}

$pharPath = $this->fixerTmpDir . '/phpstan-fixer.phar';
$infoPath = $this->fixerTmpDir . '/phar-info.json';
$pharPath = $this->proTmpDir . '/phpstan-fixer.phar';
$infoPath = $this->proTmpDir . '/phar-info.json';

try {
$this->downloadPhar($output, $pharPath, $infoPath);
Expand Down Expand Up @@ -237,7 +237,7 @@ private function getFixerProcess(OutputInterface $output, int $serverPort): Proc
}

$env = getenv();
$env['PHPSTAN_PRO_TMP_DIR'] = $this->fixerTmpDir;
$env['PHPSTAN_PRO_TMP_DIR'] = $this->proTmpDir;
$forcedPort = $_SERVER['PHPSTAN_PRO_WEB_PORT'] ?? null;
if ($forcedPort !== null) {
$env['PHPSTAN_PRO_WEB_PORT'] = $_SERVER['PHPSTAN_PRO_WEB_PORT'];
Expand All @@ -249,7 +249,7 @@ private function getFixerProcess(OutputInterface $output, int $serverPort): Proc
$output->writeln(sprintf(' <fg=cyan>-p 127.0.0.1:%d:%d</>', $_SERVER['PHPSTAN_PRO_WEB_PORT'], $_SERVER['PHPSTAN_PRO_WEB_PORT']));
$output->writeln('2) Map the temp directory to a persistent volume');
$output->writeln(' so that you don\'t have to log in every time:');
$output->writeln(sprintf(' <fg=cyan>-v ~/.phpstan-pro:%s</>', $this->fixerTmpDir));
$output->writeln(sprintf(' <fg=cyan>-v ~/.phpstan-pro:%s</>', $this->proTmpDir));
$output->writeln('');
}
} else {
Expand All @@ -265,7 +265,7 @@ private function getFixerProcess(OutputInterface $output, int $serverPort): Proc
$output->writeln(' <fg=cyan>-p 127.0.0.1:11111:11111</>');
$output->writeln('4) Map the temp directory to a persistent volume');
$output->writeln(' so that you don\'t have to log in every time:');
$output->writeln(sprintf(' <fg=cyan>-v ~/phpstan-pro:%s</>', $this->fixerTmpDir));
$output->writeln(sprintf(' <fg=cyan>-v ~/phpstan-pro:%s</>', $this->proTmpDir));
$output->writeln('');
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
use function sprintf;
use function str_ends_with;
use function substr;
use function sys_get_temp_dir;
use function time;
use function unlink;

Expand Down Expand Up @@ -133,7 +132,6 @@ public function create(
'generateBaselineFile' => $generateBaselineFile,
'usedLevel' => $usedLevel,
'cliAutoloadFile' => $cliAutoloadFile,
'fixerTmpDir' => sys_get_temp_dir() . '/phpstan-fixer',
]);
$configurator->addDynamicParameters([
'analysedPaths' => $analysedPaths,
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/NeonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class NeonAdapter implements Adapter
{

public const CACHE_KEY = 'v20-env';
public const CACHE_KEY = 'v23-pro-tmp-dir';

private const PREVENT_MERGING_SUFFIX = '!';

Expand Down Expand Up @@ -112,6 +112,7 @@ public function process(array $arr, string $fileKey, string $file): array
'[parameters][scanFiles][]',
'[parameters][scanDirectories][]',
'[parameters][tmpDir]',
'[parameters][pro][tmpDir]',
'[parameters][memoryLimitFile]',
'[parameters][benchmarkFile]',
'[parameters][stubFiles][]',
Expand Down

0 comments on commit 7c4ef6b

Please sign in to comment.