add jean85-pretty-version (#4141)

This commit is contained in:
Tomas Votruba 2020-09-08 03:12:41 +02:00 committed by GitHub
parent a03446e139
commit a32b4fed64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 7 deletions

View File

@ -15,11 +15,11 @@
"composer/xdebug-handler": "^1.4",
"doctrine/annotations": "^1.10.4",
"doctrine/inflector": "^1.4|^2.0",
"jean85/pretty-package-versions": "^1.2",
"migrify/php-config-printer": "^0.3.31",
"nette/robot-loader": "^3.2",
"nette/utils": "^3.1",
"nikic/php-parser": "4.9.0",
"ocramius/package-versions": "^1.9",
"ondram/ci-detector": "^3.4",
"phpstan/phpdoc-parser": "^0.4.9",
"phpstan/phpstan": "^0.12.38",
@ -48,7 +48,6 @@
"migrify/easy-ci": "^0.3.31",
"nette/application": "^3.0",
"nette/forms": "^3.0",
"ocramius/package-versions": "^1.4|^1.5",
"phpunit/phpunit": "^8.5|^9.2",
"psr/event-dispatcher": "^1.0",
"slam/phpstan-extensions": "^5.0",

View File

@ -4,12 +4,13 @@ declare(strict_types=1);
namespace Rector\Core\Configuration;
use Jean85\PrettyVersions;
use OndraM\CiDetector\CiDetector;
use PackageVersions\Versions;
use Rector\ChangesReporting\Output\CheckstyleOutputFormatter;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Core\Exception\Configuration\InvalidConfigurationException;
use Rector\Core\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Rector\Core\ValueObject\Jean85\Version;
use Symfony\Component\Console\Input\InputInterface;
use Symplify\PackageBuilder\Parameter\ParameterProvider;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -169,8 +170,7 @@ final class Configuration
public function getPrettyVersion(): string
{
$version = PrettyVersions::getVersion('rector/rector');
$version = new Version(Versions::getVersion('rector/rector'));
return $version->getPrettyVersion();
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Core\Console;
use Composer\XdebugHandler\XdebugHandler;
use Jean85\PrettyVersions;
use OutOfBoundsException;
use Rector\ChangesReporting\Output\CheckstyleOutputFormatter;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
@ -40,7 +39,7 @@ final class Application extends SymfonyApplication
public function __construct(Configuration $configuration, array $commands = [])
{
try {
$version = PrettyVersions::getVersion('rector/rector')->getPrettyVersion();
$version = $configuration->getPrettyVersion();
} catch (OutOfBoundsException $outOfBoundsException) {
$version = 'Unknown';
}

View File

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Rector\Core\ValueObject\Jean85;
use Nette\Utils\Strings;
/**
* Temporary local fork, until PHP 8.0 gets merged and tagged
* https://github.com/Jean85/pretty-package-versions/pull/25
*/
final class Version
{
/**
* @var int
*/
private const SHORT_COMMIT_LENGTH = 7;
/**
* @var string
*/
private $shortVersion;
/**
* @var string
*/
private $commitHash;
/**
* @var bool
*/
private $versionIsTagged = false;
public function __construct(string $version)
{
$splittedVersion = explode('@', $version);
$this->shortVersion = $splittedVersion[0];
$this->commitHash = $splittedVersion[1];
$this->versionIsTagged = (bool) Strings::match($this->shortVersion, '#[^v\d\.]#');
}
public function getPrettyVersion(): string
{
if ($this->versionIsTagged) {
return $this->shortVersion;
}
return $this->getVersionWithShortCommit();
}
private function getVersionWithShortCommit(): string
{
return $this->shortVersion . '@' . $this->getShortCommitHash();
}
private function getShortCommitHash(): string
{
return Strings::substring($this->commitHash, 0, self::SHORT_COMMIT_LENGTH);
}
}