Updated Rector to commit d2064068055fb25da2c245515a6c6260fbe6a597

d206406805 [PHP 8.1] Add other methods to ClassFromEnumFactory
This commit is contained in:
Tomas Votruba 2022-12-01 18:05:56 +00:00
parent 3d2c841cea
commit 5e2e700040
6 changed files with 89 additions and 17 deletions

View File

@ -26,15 +26,16 @@ final class ClassFromEnumFactory
public function createFromEnum(Enum_ $enum) : Class_ public function createFromEnum(Enum_ $enum) : Class_
{ {
$shortClassName = $this->nodeNameResolver->getShortName($enum); $shortClassName = $this->nodeNameResolver->getShortName($enum);
$classConsts = []; $classStmts = [];
foreach ($enum->stmts as $stmt) { foreach ($enum->stmts as $stmt) {
if (!$stmt instanceof EnumCase) { if (!$stmt instanceof EnumCase) {
$classStmts[] = $stmt;
continue; continue;
} }
$constValue = $this->createConstValue($stmt); $constValue = $this->createConstValue($stmt);
$classConsts[] = new ClassConst([new Const_($stmt->name, $constValue)], Visibility::PUBLIC); $classStmts[] = new ClassConst([new Const_($stmt->name, $constValue)], Visibility::PUBLIC);
} }
$class = new Class_($shortClassName, ['stmts' => $classConsts]); $class = new Class_($shortClassName, ['stmts' => $classStmts]);
$class->namespacedName = $enum->namespacedName; $class->namespacedName = $enum->namespacedName;
return $class; return $class;
} }

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '4e15a691a006b0ee95df856ac18f8a2b399ccfad'; public const PACKAGE_VERSION = 'd2064068055fb25da2c245515a6c6260fbe6a597';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2022-12-01 18:56:43'; public const RELEASE_DATE = '2022-12-01 19:02:13';
/** /**
* @var int * @var int
*/ */

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitd8e1eb79b4b61cc3ae04fef368f8f991::getLoader(); return ComposerAutoloaderInitf22ad65e12742e0fc5781b13aafc2fbf::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInitd8e1eb79b4b61cc3ae04fef368f8f991 class ComposerAutoloaderInitf22ad65e12742e0fc5781b13aafc2fbf
{ {
private static $loader; private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitd8e1eb79b4b61cc3ae04fef368f8f991
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInitd8e1eb79b4b61cc3ae04fef368f8f991', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInitf22ad65e12742e0fc5781b13aafc2fbf', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitd8e1eb79b4b61cc3ae04fef368f8f991', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInitf22ad65e12742e0fc5781b13aafc2fbf', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInitf22ad65e12742e0fc5781b13aafc2fbf::getInitializer($loader));
$loader->setClassMapAuthoritative(true); $loader->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991::$files; $includeFiles = \Composer\Autoload\ComposerStaticInitf22ad65e12742e0fc5781b13aafc2fbf::$files;
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequired8e1eb79b4b61cc3ae04fef368f8f991($fileIdentifier, $file); composerRequiref22ad65e12742e0fc5781b13aafc2fbf($fileIdentifier, $file);
} }
return $loader; return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitd8e1eb79b4b61cc3ae04fef368f8f991
* @param string $file * @param string $file
* @return void * @return void
*/ */
function composerRequired8e1eb79b4b61cc3ae04fef368f8f991($fileIdentifier, $file) function composerRequiref22ad65e12742e0fc5781b13aafc2fbf($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991 class ComposerStaticInitf22ad65e12742e0fc5781b13aafc2fbf
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3046,9 +3046,9 @@ class ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInitf22ad65e12742e0fc5781b13aafc2fbf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInitf22ad65e12742e0fc5781b13aafc2fbf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd8e1eb79b4b61cc3ae04fef368f8f991::$classMap; $loader->classMap = ComposerStaticInitf22ad65e12742e0fc5781b13aafc2fbf::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -16,4 +16,75 @@ class AnsiColorMode
public const Ansi4 = 'ansi4'; public const Ansi4 = 'ansi4';
public const Ansi8 = 'ansi8'; public const Ansi8 = 'ansi8';
public const Ansi24 = 'ansi24'; public const Ansi24 = 'ansi24';
/**
* Converts an RGB hexadecimal color to the corresponding Ansi code.
*/
public function convertFromHexToAnsiColorCode(string $hexColor) : string
{
$hexColor = \str_replace('#', '', $hexColor);
if (3 === \strlen($hexColor)) {
$hexColor = $hexColor[0] . $hexColor[0] . $hexColor[1] . $hexColor[1] . $hexColor[2] . $hexColor[2];
}
if (6 !== \strlen($hexColor)) {
throw new InvalidArgumentException(\sprintf('Invalid "#%s" color.', $hexColor));
}
$color = \hexdec($hexColor);
$r = $color >> 16 & 255;
$g = $color >> 8 & 255;
$b = $color & 255;
switch ($this) {
case self::Ansi4:
return (string) $this->convertFromRGB($r, $g, $b);
case self::Ansi8:
return '8;5;' . (string) $this->convertFromRGB($r, $g, $b);
case self::Ansi24:
return \sprintf('8;2;%d;%d;%d', $r, $g, $b);
}
}
private function convertFromRGB(int $r, int $g, int $b) : int
{
switch ($this) {
case self::Ansi4:
return $this->degradeHexColorToAnsi4($r, $g, $b);
case self::Ansi8:
return $this->degradeHexColorToAnsi8($r, $g, $b);
default:
throw new InvalidArgumentException("RGB cannot be converted to {$this->name}.");
}
}
private function degradeHexColorToAnsi4(int $r, int $g, int $b) : int
{
if (0 === \round($this->getSaturation($r, $g, $b) / 50)) {
return 0;
}
return (int) (\round($b / 255) << 2 | \round($g / 255) << 1 | \round($r / 255));
}
private function getSaturation(int $r, int $g, int $b) : int
{
$r = $r / 255;
$g = $g / 255;
$b = $b / 255;
$v = \max($r, $g, $b);
if (0 === ($diff = $v - \min($r, $g, $b))) {
return 0;
}
return (int) ((int) $diff * 100 / $v);
}
/**
* Inspired from https://github.com/ajalt/colormath/blob/e464e0da1b014976736cf97250063248fc77b8e7/colormath/src/commonMain/kotlin/com/github/ajalt/colormath/model/Ansi256.kt code (MIT license).
*/
private function degradeHexColorToAnsi8(int $r, int $g, int $b) : int
{
if ($r === $g && $g === $b) {
if ($r < 8) {
return 16;
}
if ($r > 248) {
return 231;
}
return (int) \round(($r - 8) / 247 * 24) + 232;
} else {
return 16 + 36 * (int) \round($r / 255 * 5) + 6 * (int) \round($g / 255 * 5) + (int) \round($b / 255 * 5);
}
}
} }