-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7700cf
commit fa8e597
Showing
9 changed files
with
60 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Application; | ||
|
||
use Composer\InstalledVersions; | ||
use Nette\Utils\Strings; | ||
|
||
/** | ||
* Inspired by https://github.com/symplify/symplify/pull/3179/files | ||
* Local resolver is needed, because PHPStan is unprefixing its InstalledVersion classes and the API is changing way too often. | ||
* This makes sure it works without dependency on external conditions. | ||
*/ | ||
final class VersionResolver | ||
{ | ||
public function resolve(): string | ||
{ | ||
// give local IntalledVersions a priority above anything else | ||
$intalledVersionsFilepath = __DIR__ . '/../../vendor/composer/InstalledVersions.php'; | ||
if (file_exists($intalledVersionsFilepath)) { | ||
require_once $intalledVersionsFilepath; | ||
} | ||
|
||
$installedRawData = InstalledVersions::getRawData(); | ||
|
||
$rectorPackageData = $this->resolvePackageData($installedRawData); | ||
if ($rectorPackageData === null) { | ||
return 'Unknown'; | ||
} | ||
|
||
if (isset($rectorPackageData['replaced'])) { | ||
return 'replaced@' . $rectorPackageData['replaced'][0]; | ||
} | ||
|
||
if ($rectorPackageData['version'] === 'dev-main') { | ||
$reference = $rectorPackageData['reference'] ?? null; | ||
if ($reference === null) { | ||
return 'dev-main'; | ||
} | ||
|
||
return 'dev-main@' . Strings::substring($rectorPackageData['reference'], 0, 7); | ||
} | ||
|
||
return $rectorPackageData['version']; | ||
} | ||
|
||
/** | ||
* @param mixed[] $installedRawData | ||
*/ | ||
private function resolvePackageData(array $installedRawData): ?array | ||
{ | ||
return $installedRawData['versions']['rector/rector-src'] ?? $installedRawData['versions']['rector/rector'] ?? $installedRawData['root'] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters