-
-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rectorphp/rector-src@fa8e597 Use local version resolver (#36)
- Loading branch information
1 parent
df00621
commit 4c713c7
Showing
30 changed files
with
71 additions
and
3,620 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace Rector\Core\Application; | ||
|
||
use RectorPrefix20210514\Composer\InstalledVersions; | ||
use RectorPrefix20210514\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 = \RectorPrefix20210514\Composer\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@' . \RectorPrefix20210514\Nette\Utils\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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.