Skip to content

Commit

Permalink
PHPStan Pro - refer branch for downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 8, 2023
1 parent 34fc187 commit be637c2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Command/FixerApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,20 @@ private function downloadPhar(
): void
{
$currentVersion = null;
$branch = 'master';
if (is_file($pharPath) && is_file($infoPath)) {
/** @var array{version: string, date: string} $currentInfo */

Check failure on line 283 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 283 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.
$currentInfo = Json::decode(FileReader::read($infoPath), Json::FORCE_ARRAY);
$currentVersion = $currentInfo['version'];
$currentBranch = $currentInfo['branch'] ?? 'master';

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 286 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.
$currentDate = DateTime::createFromFormat(DateTime::ATOM, $currentInfo['date']);
if ($currentDate === false) {
throw new ShouldNotHappenException();
}
if ((new DateTimeImmutable('', new DateTimeZone('UTC'))) <= $currentDate->modify('+24 hours')) {
if (
$currentBranch === $branch

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Offset 'branch' on array{version: string, date: string} on left side of ?? does not exist.

Check failure on line 292 in src/Command/FixerApplication.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Strict comparison using === between 'master' and 'master' will always evaluate to true.
&& (new DateTimeImmutable('', new DateTimeZone('UTC'))) <= $currentDate->modify('+24 hours')
) {
return;
}

Expand All @@ -311,9 +316,9 @@ private function downloadPhar(
/**
* @var array{url: string, version: string} $latestInfo
*/
$latestInfo = Json::decode((string) await($client->get(sprintf('https://fixer-download-api.phpstan.com/latest?%s', http_build_query(['phpVersion' => PHP_VERSION_ID]))))->getBody(), Json::FORCE_ARRAY);
$latestInfo = Json::decode((string) await($client->get(sprintf('https://fixer-download-api.phpstan.com/latest?%s', http_build_query(['phpVersion' => PHP_VERSION_ID, 'branch' => $branch]))))->getBody(), Json::FORCE_ARRAY);
if ($currentVersion !== null && $latestInfo['version'] === $currentVersion) {
$this->writeInfoFile($infoPath, $latestInfo['version']);
$this->writeInfoFile($infoPath, $latestInfo['version'], $branch);
$output->writeln('<fg=green>You\'re running the latest PHPStan Pro!</>');
return;
}
Expand Down Expand Up @@ -354,7 +359,7 @@ private function downloadPhar(
$output->writeln('');
$output->writeln('');

$this->writeInfoFile($infoPath, $latestInfo['version']);
$this->writeInfoFile($infoPath, $latestInfo['version'], $branch);
}

private function printDownloadError(OutputInterface $output, Throwable $e): void
Expand All @@ -370,10 +375,11 @@ private function printDownloadError(OutputInterface $output, Throwable $e): void
$output->writeln('');
}

private function writeInfoFile(string $infoPath, string $version): void
private function writeInfoFile(string $infoPath, string $version, string $branch): void
{
FileWriter::write($infoPath, Json::encode([
'version' => $version,
'branch' => $branch,
'date' => (new DateTimeImmutable('', new DateTimeZone('UTC')))->format(DateTime::ATOM),
]));
}
Expand Down

0 comments on commit be637c2

Please sign in to comment.