mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 2d6dba4055c239757c0d42dc09be955174ef7415
2d6dba4055
[DX] Check php version features parameter type (#983)
This commit is contained in:
parent
8a34eb9bd8
commit
b45a2137a9
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'aae9a4049ad5992052bafa1f37953681190e2404';
|
||||
public const PACKAGE_VERSION = '2d6dba4055c239757c0d42dc09be955174ef7415';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-10-12 11:01:26';
|
||||
public const RELEASE_DATE = '2021-10-12 09:27:15';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211012\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
@ -3,8 +3,11 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\Php;
|
||||
|
||||
use RectorPrefix20211012\Nette\Utils\Strings;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Exception\Configuration\InvalidConfigurationException;
|
||||
use Rector\Core\Php\PhpVersionResolver\ProjectComposerJsonPhpVersionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
|
||||
use RectorPrefix20211012\Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
/**
|
||||
@ -12,6 +15,11 @@ use RectorPrefix20211012\Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
*/
|
||||
final class PhpVersionProvider
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/qBMnbl/1
|
||||
*/
|
||||
private const VALID_PHP_VERSION_REGEX = '#^\\d{5,6}$#';
|
||||
/**
|
||||
* @var \Symplify\PackageBuilder\Parameter\ParameterProvider
|
||||
*/
|
||||
@ -27,14 +35,15 @@ final class PhpVersionProvider
|
||||
}
|
||||
public function provide() : int
|
||||
{
|
||||
$phpVersionFeatures = $this->parameterProvider->provideIntParameter(\Rector\Core\Configuration\Option::PHP_VERSION_FEATURES);
|
||||
$phpVersionFeatures = $this->parameterProvider->provideParameter(\Rector\Core\Configuration\Option::PHP_VERSION_FEATURES);
|
||||
$this->validatePhpVersionFeaturesParameter($phpVersionFeatures);
|
||||
if ($phpVersionFeatures > 0) {
|
||||
return $phpVersionFeatures;
|
||||
}
|
||||
// for tests
|
||||
if (\Rector\Testing\PHPUnit\StaticPHPUnitEnvironment::isPHPUnitRun()) {
|
||||
// so we don't have to up
|
||||
return 100000;
|
||||
// so we don't have to keep with up with newest version
|
||||
return \Rector\Core\ValueObject\PhpVersion::PHP_10;
|
||||
}
|
||||
$projectComposerJson = \getcwd() . '/composer.json';
|
||||
if (\file_exists($projectComposerJson)) {
|
||||
@ -49,4 +58,31 @@ final class PhpVersionProvider
|
||||
{
|
||||
return $phpVersion <= $this->provide();
|
||||
}
|
||||
/**
|
||||
* @param mixed $phpVersionFeatures
|
||||
*/
|
||||
private function validatePhpVersionFeaturesParameter($phpVersionFeatures) : void
|
||||
{
|
||||
if ($phpVersionFeatures === null) {
|
||||
return;
|
||||
}
|
||||
if (\Rector\Core\ValueObject\PhpVersion::isValid($phpVersionFeatures)) {
|
||||
return;
|
||||
}
|
||||
if (!\is_int($phpVersionFeatures)) {
|
||||
$this->throwInvalidTypeException($phpVersionFeatures);
|
||||
}
|
||||
if (\RectorPrefix20211012\Nette\Utils\Strings::match((string) $phpVersionFeatures, self::VALID_PHP_VERSION_REGEX) && $phpVersionFeatures >= \Rector\Core\ValueObject\PhpVersion::PHP_53 - 1) {
|
||||
return;
|
||||
}
|
||||
$this->throwInvalidTypeException($phpVersionFeatures);
|
||||
}
|
||||
/**
|
||||
* @param mixed $phpVersionFeatures
|
||||
*/
|
||||
private function throwInvalidTypeException($phpVersionFeatures) : void
|
||||
{
|
||||
$errorMessage = \sprintf('Parameter "%s::%s" must be int, "%s" given.%sUse constant from "%s" to provide it, e.g. "%s::%s"', \Rector\Core\Configuration\Option::class, 'PHP_VERSION_FEATURES', (string) $phpVersionFeatures, \PHP_EOL, \Rector\Core\ValueObject\PhpVersion::class, \Rector\Core\ValueObject\PhpVersion::class, 'PHP_80');
|
||||
throw new \Rector\Core\Exception\Configuration\InvalidConfigurationException($errorMessage);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\ValueObject;
|
||||
|
||||
final class PhpVersion
|
||||
use RectorPrefix20211012\MyCLabs\Enum\Enum;
|
||||
final class PhpVersion extends \RectorPrefix20211012\MyCLabs\Enum\Enum
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
|
@ -15,7 +15,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
]);
|
||||
|
||||
// Define what rule sets will be applied
|
||||
$containerConfigurator->import(SetList::CODE_QUALITY);
|
||||
$containerConfigurator->import(SetList::DEAD_CODE);
|
||||
|
||||
// get services (needed for register a single rule)
|
||||
// $services = $containerConfigurator->services();
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657::getLoader();
|
||||
return ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec::getLoader();
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657
|
||||
class ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit0a64b28f1180a94c06b3d8b454150657::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit69d89db6affef9ba6843514e201c60ec::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit0a64b28f1180a94c06b3d8b454150657::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit69d89db6affef9ba6843514e201c60ec::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire0a64b28f1180a94c06b3d8b454150657($fileIdentifier, $file);
|
||||
composerRequire69d89db6affef9ba6843514e201c60ec($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire0a64b28f1180a94c06b3d8b454150657($fileIdentifier, $file)
|
||||
function composerRequire69d89db6affef9ba6843514e201c60ec($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit0a64b28f1180a94c06b3d8b454150657
|
||||
class ComposerStaticInit69d89db6affef9ba6843514e201c60ec
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
@ -3891,9 +3891,9 @@ class ComposerStaticInit0a64b28f1180a94c06b3d8b454150657
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0a64b28f1180a94c06b3d8b454150657::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit0a64b28f1180a94c06b3d8b454150657::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit0a64b28f1180a94c06b3d8b454150657::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit69d89db6affef9ba6843514e201c60ec::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit69d89db6affef9ba6843514e201c60ec::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit69d89db6affef9ba6843514e201c60ec::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
||||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20211012\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657', false) && !interface_exists('ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657', false) && !trait_exists('ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657', false)) {
|
||||
spl_autoload_call('RectorPrefix20211012\ComposerAutoloaderInit0a64b28f1180a94c06b3d8b454150657');
|
||||
if (!class_exists('ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec', false) && !interface_exists('ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec', false) && !trait_exists('ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec', false)) {
|
||||
spl_autoload_call('RectorPrefix20211012\ComposerAutoloaderInit69d89db6affef9ba6843514e201c60ec');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20211012\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20211012\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire0a64b28f1180a94c06b3d8b454150657')) {
|
||||
function composerRequire0a64b28f1180a94c06b3d8b454150657() {
|
||||
return \RectorPrefix20211012\composerRequire0a64b28f1180a94c06b3d8b454150657(...func_get_args());
|
||||
if (!function_exists('composerRequire69d89db6affef9ba6843514e201c60ec')) {
|
||||
function composerRequire69d89db6affef9ba6843514e201c60ec() {
|
||||
return \RectorPrefix20211012\composerRequire69d89db6affef9ba6843514e201c60ec(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user