2021-05-14 21:57:41 +00:00
< ? php
2021-05-19 00:22:02 +00:00
declare ( strict_types = 1 );
2021-05-14 21:57:41 +00:00
namespace Rector\Core\Application ;
2021-05-19 08:27:31 +00:00
use DateTime ;
2021-05-19 00:12:47 +00:00
use Rector\Core\Exception\VersionException ;
2022-05-27 10:39:50 +00:00
use RectorPrefix20220527\Symfony\Component\Console\Command\Command ;
use RectorPrefix20220527\Symfony\Component\Process\Process ;
2021-05-14 21:57:41 +00:00
/**
2021-05-19 00:12:47 +00:00
* Inspired by https :// github . com / composer / composer / blob / master / src / Composer / Composer . php
* See https :// github . com / composer / composer / blob / 6587715 d0f8cae0cd39073b3bc5f018d0e6b84fe / src / Composer / Compiler . php #L208
2021-05-14 21:57:41 +00:00
*/
final class VersionResolver
{
2021-05-19 00:12:47 +00:00
/**
* @ var string
*/
2022-05-27 15:54:40 +00:00
public const PACKAGE_VERSION = '38ed8d2f6d765cc8ca7bfa9d2c3105d05f9109ff' ;
2021-05-19 00:12:47 +00:00
/**
* @ var string
*/
2022-05-27 15:54:40 +00:00
public const RELEASE_DATE = '2022-05-27 17:48:23' ;
2022-04-15 07:29:32 +00:00
/**
* @ var string
*/
private const GIT = 'git' ;
2021-05-19 00:22:02 +00:00
public static function resolvePackageVersion () : string
2021-05-14 21:57:41 +00:00
{
2022-05-27 11:51:31 +00:00
$pointsAtProcess = new \RectorPrefix20220527\Symfony\Component\Process\Process ([ self :: GIT , 'tag' , '--points-at' ], __DIR__ );
if ( $pointsAtProcess -> run () !== \RectorPrefix20220527\Symfony\Component\Console\Command\Command :: SUCCESS ) {
throw new \Rector\Core\Exception\VersionException ( 'You must ensure to run compile from composer git repository clone and that git binary is available.' );
2022-04-14 21:57:42 +00:00
}
$tag = \trim ( $pointsAtProcess -> getOutput ());
2022-04-15 07:29:32 +00:00
if ( $tag !== '' && $tag !== '0' ) {
2022-04-14 21:57:42 +00:00
return $tag ;
}
2022-05-27 11:51:31 +00:00
$process = new \RectorPrefix20220527\Symfony\Component\Process\Process ([ self :: GIT , 'log' , '--pretty="%H"' , '-n1' , 'HEAD' ], __DIR__ );
if ( $process -> run () !== \RectorPrefix20220527\Symfony\Component\Console\Command\Command :: SUCCESS ) {
throw new \Rector\Core\Exception\VersionException ( 'You must ensure to run compile from composer git repository clone and that git binary is available.' );
2021-05-14 21:57:41 +00:00
}
2021-05-19 19:19:21 +00:00
$version = \trim ( $process -> getOutput ());
return \trim ( $version , '"' );
2021-05-14 21:57:41 +00:00
}
2022-05-27 11:51:31 +00:00
public static function resolverReleaseDateTime () : \DateTime
2021-05-14 21:57:41 +00:00
{
2022-05-27 11:51:31 +00:00
$process = new \RectorPrefix20220527\Symfony\Component\Process\Process ([ self :: GIT , 'log' , '-n1' , '--pretty=%ci' , 'HEAD' ], __DIR__ );
if ( $process -> run () !== \RectorPrefix20220527\Symfony\Component\Console\Command\Command :: SUCCESS ) {
throw new \Rector\Core\Exception\VersionException ( 'You must ensure to run compile from composer git repository clone and that git binary is available.' );
2021-05-19 00:12:47 +00:00
}
2022-05-27 11:51:31 +00:00
return new \DateTime ( \trim ( $process -> getOutput ()));
2021-05-14 21:57:41 +00:00
}
}