mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
Updated Rector to commit 2eac878f538ddd1e20346c14d402f7e93ee6033b
2eac878f53
[TypeDeclaration] Only apply false type on php 8.2+ configured on TypedPropertyFromAssignsRector (#3422)
This commit is contained in:
parent
5901355568
commit
cf1958e570
@ -39,12 +39,8 @@ final class BooleanTypeMapper implements TypeMapperInterface
|
||||
*/
|
||||
public function mapToPHPStanPhpDocTypeNode(Type $type, string $typeKind) : TypeNode
|
||||
{
|
||||
if ($this->isFalseBooleanTypeWithUnion($type)) {
|
||||
return new IdentifierTypeNode('false');
|
||||
}
|
||||
if ($type instanceof ConstantBooleanType) {
|
||||
// cannot be parent of union
|
||||
return new IdentifierTypeNode('true');
|
||||
return new IdentifierTypeNode($type->getValue() ? 'true' : 'false');
|
||||
}
|
||||
return new IdentifierTypeNode('bool');
|
||||
}
|
||||
@ -56,19 +52,12 @@ final class BooleanTypeMapper implements TypeMapperInterface
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isFalseBooleanTypeWithUnion($type)) {
|
||||
return new Identifier('false');
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NULL_FALSE_TRUE_STANDALONE_TYPE)) {
|
||||
return new Identifier('bool');
|
||||
}
|
||||
return new Identifier('bool');
|
||||
}
|
||||
private function isFalseBooleanTypeWithUnion(Type $type) : bool
|
||||
{
|
||||
if (!$type instanceof ConstantBooleanType) {
|
||||
return \false;
|
||||
return new Identifier('bool');
|
||||
}
|
||||
if ($type->getValue()) {
|
||||
return \false;
|
||||
}
|
||||
return $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES);
|
||||
return $type->getValue() ? new Identifier('true') : new Identifier('false');
|
||||
}
|
||||
}
|
||||
|
@ -331,12 +331,9 @@ final class UnionTypeMapper implements TypeMapperInterface
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* NullType inside UnionType is allowed
|
||||
* make it on TypeKind property as changing other type, eg: return type may conflict with parent child implementation
|
||||
*
|
||||
* @var Identifier|Name|null|PHPParserNodeIntersectionType $phpParserNode
|
||||
* NullType or ConstantBooleanType with false value inside UnionType is allowed
|
||||
*/
|
||||
$phpParserNode = $unionedType instanceof NullType && $typeKind === TypeKind::PROPERTY ? new Identifier('null') : $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionedType, $typeKind);
|
||||
$phpParserNode = $this->resolveAllowedStandaloneTypeInUnionType($unionedType, $typeKind);
|
||||
if ($phpParserNode === null) {
|
||||
return null;
|
||||
}
|
||||
@ -353,6 +350,20 @@ final class UnionTypeMapper implements TypeMapperInterface
|
||||
}
|
||||
return $this->resolveTypeWithNullablePHPParserUnionType(new PhpParserUnionType($phpParserUnionedTypes));
|
||||
}
|
||||
/**
|
||||
* @param TypeKind::* $typeKind
|
||||
* @return \PhpParser\Node\Identifier|\PhpParser\Node\Name|null|PHPParserNodeIntersectionType|\PhpParser\Node\ComplexType
|
||||
*/
|
||||
private function resolveAllowedStandaloneTypeInUnionType(Type $unionedType, string $typeKind)
|
||||
{
|
||||
if ($unionedType instanceof NullType) {
|
||||
return new Identifier('null');
|
||||
}
|
||||
if ($unionedType instanceof ConstantBooleanType && !$unionedType->getValue()) {
|
||||
return new Identifier('false');
|
||||
}
|
||||
return $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionedType, $typeKind);
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\UnionType|\PHPStan\Type\TypeWithClassName|null
|
||||
*/
|
||||
|
@ -13,7 +13,6 @@ use PHPStan\Reflection\FunctionVariantWithPhpDocs;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\Core\FileSystem\FilePathHelper;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
@ -102,6 +101,12 @@ final class ClassMethodReturnTypeOverrideGuard
|
||||
if (!$classReflection instanceof ClassReflection) {
|
||||
return \true;
|
||||
}
|
||||
if ($classReflection->isAbstract()) {
|
||||
return \true;
|
||||
}
|
||||
if ($classReflection->isInterface()) {
|
||||
return \true;
|
||||
}
|
||||
if (!$this->isReturnTypeChangeAllowed($classMethod)) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ CODE_SAMPLE
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|New_|MethodCall|StaticCall $node
|
||||
* @return \PhpParser\Node\Stmt\ClassMethod|null|\PhpParser\Node\Expr\New_|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope)
|
||||
{
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '96176848192e3214a7a311126925ffeb9912e2e5';
|
||||
public const PACKAGE_VERSION = '2eac878f538ddd1e20346c14d402f7e93ee6033b';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-02-28 17:45:04';
|
||||
public const RELEASE_DATE = '2023-03-01 01:18:39';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -50,7 +50,7 @@ final class ConstantStringTypeToCallReflectionResolver implements TypeToCallRefl
|
||||
}
|
||||
/**
|
||||
* @param ConstantStringType $type
|
||||
* @return FunctionReflection|MethodReflection|null
|
||||
* @return \PHPStan\Reflection\FunctionReflection|\PHPStan\Reflection\MethodReflection|null
|
||||
*/
|
||||
public function resolve(Type $type, Scope $scope)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ final class TypeToCallReflectionResolverRegistry
|
||||
$this->resolvers = $resolvers;
|
||||
}
|
||||
/**
|
||||
* @return FunctionReflection|MethodReflection|null
|
||||
* @return \PHPStan\Reflection\FunctionReflection|\PHPStan\Reflection\MethodReflection|null
|
||||
*/
|
||||
public function resolve(Type $type, Scope $scope)
|
||||
{
|
||||
|
@ -497,4 +497,11 @@ final class PhpVersionFeature
|
||||
* @var int
|
||||
*/
|
||||
public const FILESYSTEM_ITERATOR_SKIP_DOTS = \Rector\Core\ValueObject\PhpVersion::PHP_82;
|
||||
/**
|
||||
* @see https://wiki.php.net/rfc/null-false-standalone-types
|
||||
* @see https://wiki.php.net/rfc/true-type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public const NULL_FALSE_TRUE_STANDALONE_TYPE = \Rector\Core\ValueObject\PhpVersion::PHP_82;
|
||||
}
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit3da4ef8eae34d1e99e00f4687ea42ad0::getLoader();
|
||||
return ComposerAutoloaderInit931c0d2eaf587d3a9322637e254e6263::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit3da4ef8eae34d1e99e00f4687ea42ad0
|
||||
class ComposerAutoloaderInit931c0d2eaf587d3a9322637e254e6263
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit3da4ef8eae34d1e99e00f4687ea42ad0
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3da4ef8eae34d1e99e00f4687ea42ad0', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit931c0d2eaf587d3a9322637e254e6263', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3da4ef8eae34d1e99e00f4687ea42ad0', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit931c0d2eaf587d3a9322637e254e6263', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit931c0d2eaf587d3a9322637e254e6263::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit931c0d2eaf587d3a9322637e254e6263::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0
|
||||
class ComposerStaticInit931c0d2eaf587d3a9322637e254e6263
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3126,9 +3126,9 @@ class ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3da4ef8eae34d1e99e00f4687ea42ad0::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit931c0d2eaf587d3a9322637e254e6263::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit931c0d2eaf587d3a9322637e254e6263::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit931c0d2eaf587d3a9322637e254e6263::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class LoaderResolver implements LoaderResolverInterface
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return \Symfony\Component\Config\Loader\LoaderInterface|true
|
||||
* @return \Symfony\Component\Config\Loader\LoaderInterface|false
|
||||
* @param mixed $resource
|
||||
*/
|
||||
public function resolve($resource, string $type = null)
|
||||
|
@ -21,7 +21,7 @@ interface LoaderResolverInterface
|
||||
* Returns a loader able to load the resource.
|
||||
*
|
||||
* @param string|null $type The resource type or null if unknown
|
||||
* @return \Symfony\Component\Config\Loader\LoaderInterface|true
|
||||
* @return \Symfony\Component\Config\Loader\LoaderInterface|false
|
||||
* @param mixed $resource
|
||||
*/
|
||||
public function resolve($resource, string $type = null);
|
||||
|
@ -426,7 +426,7 @@ class QuestionHelper extends Helper
|
||||
*
|
||||
* @param resource $inputStream The handler resource
|
||||
* @param Question $question The question being asked
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
private function readInput($inputStream, Question $question)
|
||||
{
|
||||
@ -460,8 +460,8 @@ class QuestionHelper extends Helper
|
||||
}
|
||||
/**
|
||||
* Sets console I/O to the specified code page and converts the user input.
|
||||
* @param string|true $input
|
||||
* @return string|true
|
||||
* @param string|false $input
|
||||
* @return string|false
|
||||
*/
|
||||
private function resetIOCodepage(int $cp, $input)
|
||||
{
|
||||
|
@ -333,7 +333,7 @@ class Container implements ContainerInterface, ResetInterface
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* @param string|true $registry
|
||||
* @param string|false $registry
|
||||
* @param string|bool $load
|
||||
* @return mixed
|
||||
*/
|
||||
|
2
vendor/symfony/finder/Finder.php
vendored
2
vendor/symfony/finder/Finder.php
vendored
@ -79,7 +79,7 @@ class Finder implements \IteratorAggregate, \Countable
|
||||
*/
|
||||
private $reverseSorting = \false;
|
||||
/**
|
||||
* @var \Closure|int|true
|
||||
* @var \Closure|int|false
|
||||
*/
|
||||
private $sort = \false;
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ if (!function_exists('normalizer_is_normalized')) {
|
||||
}
|
||||
if (!function_exists('normalizer_normalize')) {
|
||||
/**
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function normalizer_normalize(?string $string, ?int $form = p\Normalizer::FORM_C) { return p\Normalizer::normalize((string) $string, (int) $form); }
|
||||
}
|
||||
|
30
vendor/symfony/polyfill-mbstring/bootstrap80.php
vendored
30
vendor/symfony/polyfill-mbstring/bootstrap80.php
vendored
@ -15,7 +15,7 @@ if (!function_exists('mb_convert_encoding')) {
|
||||
/**
|
||||
* @param mixed[]|string|null $string
|
||||
* @param mixed[]|string|null $from_encoding
|
||||
* @return mixed[]|string|true
|
||||
* @return mixed[]|string|false
|
||||
*/
|
||||
function mb_convert_encoding($string, ?string $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); }
|
||||
}
|
||||
@ -61,7 +61,7 @@ if (!function_exists('mb_check_encoding')) {
|
||||
if (!function_exists('mb_detect_encoding')) {
|
||||
/**
|
||||
* @param mixed[]|string|null $encodings
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function mb_detect_encoding(?string $string, $encodings = null, ?bool $strict = false) { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); }
|
||||
}
|
||||
@ -80,7 +80,7 @@ if (!function_exists('mb_strlen')) {
|
||||
}
|
||||
if (!function_exists('mb_strpos')) {
|
||||
/**
|
||||
* @return int|true
|
||||
* @return int|false
|
||||
*/
|
||||
function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null) { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
@ -102,49 +102,49 @@ if (!function_exists('mb_substr')) {
|
||||
}
|
||||
if (!function_exists('mb_stripos')) {
|
||||
/**
|
||||
* @return int|true
|
||||
* @return int|false
|
||||
*/
|
||||
function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null) { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stristr')) {
|
||||
/**
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null) { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrchr')) {
|
||||
/**
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null) { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrichr')) {
|
||||
/**
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null) { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strripos')) {
|
||||
/**
|
||||
* @return int|true
|
||||
* @return int|false
|
||||
*/
|
||||
function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null) { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrpos')) {
|
||||
/**
|
||||
* @return int|true
|
||||
* @return int|false
|
||||
*/
|
||||
function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null) { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strstr')) {
|
||||
/**
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null) { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_get_info')) {
|
||||
/**
|
||||
* @return mixed[]|string|int|true
|
||||
* @return mixed[]|string|int|false
|
||||
*/
|
||||
function mb_get_info(?string $type = 'all') { return p\Mbstring::mb_get_info((string) $type); }
|
||||
}
|
||||
@ -165,7 +165,7 @@ if (!function_exists('mb_output_handler')) {
|
||||
}
|
||||
if (!function_exists('mb_http_input')) {
|
||||
/**
|
||||
* @return mixed[]|string|true
|
||||
* @return mixed[]|string|false
|
||||
*/
|
||||
function mb_http_input(?string $type = null) { return p\Mbstring::mb_http_input($type); }
|
||||
}
|
||||
@ -173,7 +173,7 @@ if (!function_exists('mb_http_input')) {
|
||||
if (!function_exists('mb_convert_variables')) {
|
||||
/**
|
||||
* @param mixed[]|string|null $from_encoding
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
* @param mixed $var
|
||||
* @param mixed ...$vars
|
||||
*/
|
||||
@ -182,13 +182,13 @@ if (!function_exists('mb_convert_variables')) {
|
||||
|
||||
if (!function_exists('mb_ord')) {
|
||||
/**
|
||||
* @return int|true
|
||||
* @return int|false
|
||||
*/
|
||||
function mb_ord(?string $string, ?string $encoding = null) { return p\Mbstring::mb_ord((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_chr')) {
|
||||
/**
|
||||
* @return string|true
|
||||
* @return string|false
|
||||
*/
|
||||
function mb_chr(?int $codepoint, ?string $encoding = null) { return p\Mbstring::mb_chr((int) $codepoint, $encoding); }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user