Updated Rector to commit ff32c0c08a89f27ea34187d00cf707734a7e39c8

ff32c0c08a [Php84] Add ExplicitNullableParamTypeRector (#5724)
This commit is contained in:
Tomas Votruba 2024-03-15 10:45:55 +00:00
parent edd8901ea0
commit c0820093ad
14 changed files with 148 additions and 9 deletions

View File

@ -0,0 +1,11 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202403;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([SetList::PHP_84, LevelSetList::UP_TO_PHP_83]);
};

10
config/set/php84.php Normal file
View File

@ -0,0 +1,10 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202403;
use Rector\Config\RectorConfig;
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ExplicitNullableParamTypeRector::class]);
};

View File

@ -1,4 +1,4 @@
# 364 Rules Overview
# 365 Rules Overview
<br>
@ -46,6 +46,8 @@
- [Php83](#php83) (3)
- [Php84](#php84) (1)
- [Privatization](#privatization) (5)
- [Removing](#removing) (5)
@ -5328,6 +5330,21 @@ Combine separated host and port on `ldap_connect()` args
<br>
## Php84
### ExplicitNullableParamTypeRector
Make implicit nullable param to explicit
- class: [`Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector`](../rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php)
```diff
-function foo(string $param = null) {}
+function foo(?string $param = null) {}
```
<br>
## Privatization
### FinalizeClassesWithoutChildrenRector

View File

@ -0,0 +1,80 @@
<?php
declare (strict_types=1);
namespace Rector\Php84\Rector\Param;
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Param;
use PHPStan\Type\NullType;
use PHPStan\Type\TypeCombinator;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\Rector\AbstractRector;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Php84\Rector\Param\ExplicitNullableParamTypeRector\ExplicitNullableParamTypeRectorTest
*/
final class ExplicitNullableParamTypeRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
/**
* @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/
private $staticTypeMapper;
public function __construct(ValueResolver $valueResolver, StaticTypeMapper $staticTypeMapper)
{
$this->valueResolver = $valueResolver;
$this->staticTypeMapper = $staticTypeMapper;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Make implicit nullable param to explicit', [new CodeSample(<<<'CODE_SAMPLE'
function foo(string $param = null) {}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
function foo(?string $param = null) {}
CODE_SAMPLE
)]);
}
public function getNodeTypes() : array
{
return [Param::class];
}
/**
* @param Param $node
*/
public function refactor(Node $node) : ?Param
{
if (!$node->type instanceof Node) {
return null;
}
if (!$node->default instanceof ConstFetch || !$this->valueResolver->isNull($node->default)) {
return null;
}
$nodeType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node->type);
if ($nodeType instanceof NullType) {
return null;
}
$removedNullNodeType = TypeCombinator::removeNull($nodeType);
if (!$nodeType->equals($removedNullNodeType)) {
return null;
}
$newNodeType = TypeCombinator::addNull($nodeType);
$node->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newNodeType, TypeKind::PARAM);
return $node;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::DEPRECATE_IMPLICIT_NULLABLE_PARAM_TYPE;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '23e3da2d6eee90e4f2a31c31062aabaeba77ba69';
public const PACKAGE_VERSION = 'ff32c0c08a89f27ea34187d00cf707734a7e39c8';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-03-14 20:14:23';
public const RELEASE_DATE = '2024-03-15 11:43:37';
/**
* @var int
*/

View File

@ -313,7 +313,7 @@ final class RectorConfigBuilder
* What PHP sets should be applied? By default the same version
* as composer.json has is used
*/
public function withPhpSets(bool $php83 = \false, bool $php82 = \false, bool $php81 = \false, bool $php80 = \false, bool $php74 = \false, bool $php73 = \false, bool $php72 = \false, bool $php71 = \false, bool $php70 = \false, bool $php56 = \false, bool $php55 = \false, bool $php54 = \false, bool $php53 = \false) : self
public function withPhpSets(bool $php83 = \false, bool $php82 = \false, bool $php81 = \false, bool $php80 = \false, bool $php74 = \false, bool $php73 = \false, bool $php72 = \false, bool $php71 = \false, bool $php70 = \false, bool $php56 = \false, bool $php55 = \false, bool $php54 = \false, bool $php53 = \false, bool $php84 = \false) : self
{
$pickedArguments = \array_filter(\func_get_args());
if (\count($pickedArguments) > 1) {
@ -357,6 +357,8 @@ final class RectorConfigBuilder
$this->sets[] = LevelSetList::UP_TO_PHP_82;
} elseif ($php83) {
$this->sets[] = LevelSetList::UP_TO_PHP_83;
} elseif ($php84) {
$this->sets[] = LevelSetList::UP_TO_PHP_84;
}
return $this;
}

View File

@ -9,6 +9,10 @@ use Rector\Set\Contract\SetListInterface;
*/
final class LevelSetList implements SetListInterface
{
/**
* @var string
*/
public const UP_TO_PHP_84 = __DIR__ . '/../../../config/set/level/up-to-php84.php';
/**
* @var string
*/

View File

@ -89,6 +89,10 @@ final class SetList implements SetListInterface
* @var string
*/
public const PHP_83 = __DIR__ . '/../../../config/set/php83.php';
/**
* @var string
*/
public const PHP_84 = __DIR__ . '/../../../config/set/php84.php';
/**
* @var string
*/

View File

@ -64,6 +64,10 @@ final class PhpVersion
* @var int
*/
public const PHP_83 = 80300;
/**
* @var int
*/
public const PHP_84 = 80400;
/**
* @var int
*/

View File

@ -532,6 +532,11 @@ final class PhpVersionFeature
* @var int
*/
public const TYPED_CLASS_CONSTANTS = \Rector\ValueObject\PhpVersion::PHP_83;
/**
* @see https://wiki.php.net/rfc/deprecate-implicitly-nullable-types
* @var int
*/
public const DEPRECATE_IMPLICIT_NULLABLE_PARAM_TYPE = \Rector\ValueObject\PhpVersion::PHP_84;
/**
* @see https://www.php.net/manual/en/migration83.deprecated.php#migration83.deprecated.ldap
* @var int

View File

@ -1921,6 +1921,7 @@ return array(
'Rector\\Php83\\Rector\\ClassConst\\AddTypeToConstRector' => $baseDir . '/rules/Php83/Rector/ClassConst/AddTypeToConstRector.php',
'Rector\\Php83\\Rector\\ClassMethod\\AddOverrideAttributeToOverriddenMethodsRector' => $baseDir . '/rules/Php83/Rector/ClassMethod/AddOverrideAttributeToOverriddenMethodsRector.php',
'Rector\\Php83\\Rector\\FuncCall\\CombineHostPortLdapUriRector' => $baseDir . '/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php',
'Rector\\Php84\\Rector\\Param\\ExplicitNullableParamTypeRector' => $baseDir . '/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php',
'Rector\\PhpAttribute\\AnnotationToAttributeMapper' => $baseDir . '/src/PhpAttribute/AnnotationToAttributeMapper.php',
'Rector\\PhpAttribute\\AnnotationToAttributeMapper\\ArrayAnnotationToAttributeMapper' => $baseDir . '/src/PhpAttribute/AnnotationToAttributeMapper/ArrayAnnotationToAttributeMapper.php',
'Rector\\PhpAttribute\\AnnotationToAttributeMapper\\ArrayItemNodeAnnotationToAttributeMapper' => $baseDir . '/src/PhpAttribute/AnnotationToAttributeMapper/ArrayItemNodeAnnotationToAttributeMapper.php',

View File

@ -2140,6 +2140,7 @@ class ComposerStaticInit2d887a2f87c676eb32b3e04612865e54
'Rector\\Php83\\Rector\\ClassConst\\AddTypeToConstRector' => __DIR__ . '/../..' . '/rules/Php83/Rector/ClassConst/AddTypeToConstRector.php',
'Rector\\Php83\\Rector\\ClassMethod\\AddOverrideAttributeToOverriddenMethodsRector' => __DIR__ . '/../..' . '/rules/Php83/Rector/ClassMethod/AddOverrideAttributeToOverriddenMethodsRector.php',
'Rector\\Php83\\Rector\\FuncCall\\CombineHostPortLdapUriRector' => __DIR__ . '/../..' . '/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php',
'Rector\\Php84\\Rector\\Param\\ExplicitNullableParamTypeRector' => __DIR__ . '/../..' . '/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php',
'Rector\\PhpAttribute\\AnnotationToAttributeMapper' => __DIR__ . '/../..' . '/src/PhpAttribute/AnnotationToAttributeMapper.php',
'Rector\\PhpAttribute\\AnnotationToAttributeMapper\\ArrayAnnotationToAttributeMapper' => __DIR__ . '/../..' . '/src/PhpAttribute/AnnotationToAttributeMapper/ArrayAnnotationToAttributeMapper.php',
'Rector\\PhpAttribute\\AnnotationToAttributeMapper\\ArrayItemNodeAnnotationToAttributeMapper' => __DIR__ . '/../..' . '/src/PhpAttribute/AnnotationToAttributeMapper/ArrayItemNodeAnnotationToAttributeMapper.php',

View File

@ -504,8 +504,8 @@
},
{
"name": "illuminate\/container",
"version": "v10.48.2",
"version_normalized": "10.48.2.0",
"version": "v10.48.3",
"version_normalized": "10.48.3.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/container.git",
@ -561,8 +561,8 @@
},
{
"name": "illuminate\/contracts",
"version": "v10.48.2",
"version_normalized": "10.48.2.0",
"version": "v10.48.3",
"version_normalized": "10.48.3.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/contracts.git",

File diff suppressed because one or more lines are too long