mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-13 12:02:09 +02:00
Updated Rector to commit b9ace5f53f1640ab947922957e8179b2b50ff2cd
b9ace5f53f
[PHP 8] Resources object upgrade - remove 2 rules as the upgrade require wholesome manual work (#4442)
This commit is contained in:
parent
c409764fcc
commit
c86937fb6b
@ -18,7 +18,6 @@ use Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector;
|
||||
use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector;
|
||||
use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector;
|
||||
use Rector\Php80\Rector\FuncCall\ClassOnObjectRector;
|
||||
use Rector\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector;
|
||||
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
|
||||
use Rector\Php80\Rector\Identical\StrEndsWithRector;
|
||||
use Rector\Php80\Rector\Identical\StrStartsWithRector;
|
||||
@ -29,22 +28,12 @@ use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
|
||||
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;
|
||||
use Rector\Transform\ValueObject\StaticCallToFuncCall;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rule(StrContainsRector::class);
|
||||
$rectorConfig->rule(StrStartsWithRector::class);
|
||||
$rectorConfig->rule(StrEndsWithRector::class);
|
||||
$rectorConfig->rules([StrContainsRector::class, StrStartsWithRector::class, StrEndsWithRector::class, StringableForToStringRector::class, ClassOnObjectRector::class, GetDebugTypeRector::class, RemoveUnusedVariableInCatchRector::class, ClassPropertyAssignToConstructorPromotionRector::class, ChangeSwitchToMatchRector::class, RemoveParentCallWithoutParentRector::class, SetStateToStaticRector::class, FinalPrivateToPrivateVisibilityRector::class, AddParamBasedOnParentClassMethodRector::class, MixedTypeRector::class, ClassOnThisVariableObjectRector::class]);
|
||||
$rectorConfig->ruleWithConfiguration(StaticCallToFuncCallRector::class, [new StaticCallToFuncCall('Nette\\Utils\\Strings', 'startsWith', 'str_starts_with'), new StaticCallToFuncCall('Nette\\Utils\\Strings', 'endsWith', 'str_ends_with'), new StaticCallToFuncCall('Nette\\Utils\\Strings', 'contains', 'str_contains')]);
|
||||
$rectorConfig->rules([StringableForToStringRector::class, ClassOnObjectRector::class, GetDebugTypeRector::class, RemoveUnusedVariableInCatchRector::class, ClassPropertyAssignToConstructorPromotionRector::class, ChangeSwitchToMatchRector::class]);
|
||||
// nette\utils and Strings::replace()
|
||||
$rectorConfig->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder('Nette\\Utils\\Strings', 'replace', 2, 'replacement', '')]);
|
||||
$rectorConfig->rule(RemoveParentCallWithoutParentRector::class);
|
||||
$rectorConfig->rule(SetStateToStaticRector::class);
|
||||
$rectorConfig->rule(FinalPrivateToPrivateVisibilityRector::class);
|
||||
// @see https://php.watch/versions/8.0/pgsql-aliases-deprecated
|
||||
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, ['pg_clientencoding' => 'pg_client_encoding', 'pg_cmdtuples' => 'pg_affected_rows', 'pg_errormessage' => 'pg_last_error', 'pg_fieldisnull' => 'pg_field_is_null', 'pg_fieldname' => 'pg_field_name', 'pg_fieldnum' => 'pg_field_num', 'pg_fieldprtlen' => 'pg_field_prtlen', 'pg_fieldsize' => 'pg_field_size', 'pg_fieldtype' => 'pg_field_type', 'pg_freeresult' => 'pg_free_result', 'pg_getlastoid' => 'pg_last_oid', 'pg_loclose' => 'pg_lo_close', 'pg_locreate' => 'pg_lo_create', 'pg_loexport' => 'pg_lo_export', 'pg_loimport' => 'pg_lo_import', 'pg_loopen' => 'pg_lo_open', 'pg_loread' => 'pg_lo_read', 'pg_loreadall' => 'pg_lo_read_all', 'pg_lounlink' => 'pg_lo_unlink', 'pg_lowrite' => 'pg_lo_write', 'pg_numfields' => 'pg_num_fields', 'pg_numrows' => 'pg_num_rows', 'pg_result' => 'pg_fetch_result', 'pg_setclientencoding' => 'pg_set_client_encoding']);
|
||||
$rectorConfig->rule(OptionalParametersAfterRequiredRector::class);
|
||||
$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'lte', 'le'), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '', '!='), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, '!', '!='), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'g', 'gt'), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'l', 'lt'), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge'), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'lte', 'le'), new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'n', 'ne')]);
|
||||
$rectorConfig->rule(Php8ResourceReturnToObjectRector::class);
|
||||
$rectorConfig->rule(AddParamBasedOnParentClassMethodRector::class);
|
||||
$rectorConfig->rule(MixedTypeRector::class);
|
||||
$rectorConfig->rule(ClassOnThisVariableObjectRector::class);
|
||||
};
|
||||
|
@ -10,12 +10,11 @@ use Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector;
|
||||
use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector;
|
||||
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
|
||||
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
|
||||
use Rector\Php81\Rector\FuncCall\Php81ResourceReturnToObjectRector;
|
||||
use Rector\Php81\Rector\FunctionLike\IntersectionTypesRector;
|
||||
use Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector;
|
||||
use Rector\Php81\Rector\MethodCall\SpatieEnumMethodCallToEnumConstRector;
|
||||
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, FinalizePublicClassConstantRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, Php81ResourceReturnToObjectRector::class, NewInInitializerRector::class, IntersectionTypesRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class]);
|
||||
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, FinalizePublicClassConstantRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NewInInitializerRector::class, IntersectionTypesRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class]);
|
||||
};
|
||||
|
@ -1,207 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php80\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
final class ResourceReturnToObject
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $collectionFunctionToReturnObject
|
||||
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\BinaryOp\BooleanOr $node
|
||||
* @return \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\BinaryOp\BooleanOr|\PhpParser\Node\Expr\Instanceof_|null
|
||||
*/
|
||||
public function refactor($node, array $collectionFunctionToReturnObject)
|
||||
{
|
||||
if ($node instanceof FuncCall) {
|
||||
return $this->processFuncCall($node, $collectionFunctionToReturnObject);
|
||||
}
|
||||
return $this->processBooleanOr($node, $collectionFunctionToReturnObject);
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $collectionFunctionToReturnObject
|
||||
*/
|
||||
private function processFuncCall(FuncCall $funcCall, array $collectionFunctionToReturnObject) : ?Instanceof_
|
||||
{
|
||||
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof BinaryOp && !$parentNode instanceof BooleanOr) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkip($funcCall)) {
|
||||
return null;
|
||||
}
|
||||
$objectInstanceCheck = $this->resolveObjectInstanceCheck($funcCall, $collectionFunctionToReturnObject);
|
||||
if ($objectInstanceCheck === null) {
|
||||
return null;
|
||||
}
|
||||
$firstArg = $funcCall->getArgs()[0];
|
||||
$argResourceValue = $firstArg->value;
|
||||
return new Instanceof_($argResourceValue, new FullyQualified($objectInstanceCheck));
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $collectionFunctionToReturnObject
|
||||
*/
|
||||
private function resolveArgValueType(FuncCall $funcCall, array $collectionFunctionToReturnObject) : ?Type
|
||||
{
|
||||
$argResourceValue = $funcCall->getArgs()[0]->value;
|
||||
$argValueType = $this->nodeTypeResolver->getType($argResourceValue);
|
||||
// if detected type is not FullyQualifiedObjectType, it still can be a resource to object, when:
|
||||
// - in the right position of BooleanOr, it be NeverType
|
||||
// - the object changed after init
|
||||
if (!$argValueType instanceof FullyQualifiedObjectType) {
|
||||
return $this->resolveArgValueTypeFromPreviousAssign($funcCall, $argResourceValue, $collectionFunctionToReturnObject);
|
||||
}
|
||||
return $argValueType;
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $collectionFunctionToReturnObject
|
||||
*/
|
||||
private function resolveObjectInstanceCheck(FuncCall $funcCall, array $collectionFunctionToReturnObject) : ?string
|
||||
{
|
||||
$argValueType = $this->resolveArgValueType($funcCall, $collectionFunctionToReturnObject);
|
||||
if (!$argValueType instanceof FullyQualifiedObjectType) {
|
||||
return null;
|
||||
}
|
||||
$className = $argValueType->getClassName();
|
||||
foreach ($collectionFunctionToReturnObject as $singleCollectionFunctionToReturnObject) {
|
||||
if ($className === $singleCollectionFunctionToReturnObject) {
|
||||
return $singleCollectionFunctionToReturnObject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $collectionFunctionToReturnObject
|
||||
*/
|
||||
private function resolveArgValueTypeFromPreviousAssign(FuncCall $funcCall, Expr $expr, array $collectionFunctionToReturnObject) : ?FullyQualifiedObjectType
|
||||
{
|
||||
$objectInstanceCheck = null;
|
||||
$foundNode = $this->betterNodeFinder->findFirstPrevious($funcCall, function (Node $subNode) use(&$objectInstanceCheck, $expr, $collectionFunctionToReturnObject) : bool {
|
||||
if (!$this->isAssignWithFuncCallExpr($subNode)) {
|
||||
return \false;
|
||||
}
|
||||
/** @var Assign $subNode */
|
||||
if (!$this->nodeComparator->areNodesEqual($subNode->var, $expr)) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($collectionFunctionToReturnObject as $key => $value) {
|
||||
if ($this->nodeNameResolver->isName($subNode->expr, $key)) {
|
||||
$objectInstanceCheck = $value;
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
});
|
||||
if (!$foundNode instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
/** @var string $objectInstanceCheck */
|
||||
return new FullyQualifiedObjectType($objectInstanceCheck);
|
||||
}
|
||||
private function isAssignWithFuncCallExpr(Node $node) : bool
|
||||
{
|
||||
if (!$node instanceof Assign) {
|
||||
return \false;
|
||||
}
|
||||
return $node->expr instanceof FuncCall;
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $collectionFunctionToReturnObject
|
||||
*/
|
||||
private function processBooleanOr(BooleanOr $booleanOr, array $collectionFunctionToReturnObject) : ?Instanceof_
|
||||
{
|
||||
$left = $booleanOr->left;
|
||||
$right = $booleanOr->right;
|
||||
$funCall = null;
|
||||
$instanceof = null;
|
||||
if ($left instanceof FuncCall && $right instanceof Instanceof_) {
|
||||
$funCall = $left;
|
||||
$instanceof = $right;
|
||||
} elseif ($left instanceof Instanceof_ && $right instanceof FuncCall) {
|
||||
$funCall = $right;
|
||||
$instanceof = $left;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
/** @var FuncCall $funCall */
|
||||
if ($this->shouldSkip($funCall)) {
|
||||
return null;
|
||||
}
|
||||
$objectInstanceCheck = $this->resolveObjectInstanceCheck($funCall, $collectionFunctionToReturnObject);
|
||||
if ($objectInstanceCheck === null) {
|
||||
return null;
|
||||
}
|
||||
$argResourceValue = $funCall->getArgs()[0]->value;
|
||||
/** @var Instanceof_ $instanceof */
|
||||
if (!$this->isInstanceOfObjectCheck($instanceof, $argResourceValue, $objectInstanceCheck)) {
|
||||
return null;
|
||||
}
|
||||
return $instanceof;
|
||||
}
|
||||
private function isInstanceOfObjectCheck(Instanceof_ $instanceof, Expr $expr, string $objectInstanceCheck) : bool
|
||||
{
|
||||
if (!$instanceof->class instanceof FullyQualified) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($expr, $instanceof->expr)) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isName($instanceof->class, $objectInstanceCheck);
|
||||
}
|
||||
private function shouldSkip(FuncCall $funcCall) : bool
|
||||
{
|
||||
if (!$this->nodeNameResolver->isName($funcCall, 'is_resource')) {
|
||||
return \true;
|
||||
}
|
||||
if ($funcCall->isFirstClassCallable()) {
|
||||
return \true;
|
||||
}
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return \true;
|
||||
}
|
||||
$argResource = $funcCall->args[0];
|
||||
return !$argResource instanceof Arg;
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php80\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\Php80\NodeManipulator\ResourceReturnToObject;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.resource2object
|
||||
*
|
||||
* @see \Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Php8ResourceReturnToObjectRectorTest
|
||||
*/
|
||||
final class Php8ResourceReturnToObjectRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php80\NodeManipulator\ResourceReturnToObject
|
||||
*/
|
||||
private $resourceReturnToObject;
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const COLLECTION_FUNCTION_TO_RETURN_OBJECT = [
|
||||
// curl
|
||||
'curl_init' => 'CurlHandle',
|
||||
'curl_multi_init' => 'CurlMultiHandle',
|
||||
'curl_share_init' => 'CurlShareHandle',
|
||||
// socket
|
||||
'socket_create' => 'Socket',
|
||||
'socket_accept' => 'Socket',
|
||||
'socket_addrinfo_bind' => 'Socket',
|
||||
'socket_addrinfo_connect' => 'Socket',
|
||||
'socket_create_listen' => 'Socket',
|
||||
'socket_import_stream' => 'Socket',
|
||||
'socket_wsaprotocol_info_import' => 'Socket',
|
||||
// GD
|
||||
'imagecreate' => 'GdImage',
|
||||
'imagecreatefromavif' => 'GdImage',
|
||||
'imagecreatefrombmp' => 'GdImage',
|
||||
'imagecreatefromgd2' => 'GdImage',
|
||||
'imagecreatefromgd2part' => 'GdImage',
|
||||
'imagecreatefromgd' => 'GdImage',
|
||||
'imagecreatefromgif' => 'GdImage',
|
||||
'imagecreatefromjpeg' => 'GdImage',
|
||||
'imagecreatefrompng' => 'GdImage',
|
||||
'imagecreatefromstring' => 'GdImage',
|
||||
'imagecreatefromtga' => 'GdImage',
|
||||
'imagecreatefromwbmp' => 'GdImage',
|
||||
'imagecreatefromwebp' => 'GdImage',
|
||||
'imagecreatefromxbm' => 'GdImage',
|
||||
'imagecreatefromxpm' => 'GdImage',
|
||||
'imagecreatetruecolor' => 'GdImage',
|
||||
'imagecrop' => 'GdImage',
|
||||
'imagecropauto' => 'GdImage',
|
||||
// XMLWriter
|
||||
'xmlwriter_open_memory' => 'XMLWriter',
|
||||
// XMLParser
|
||||
'xml_parser_create' => 'XMLParser',
|
||||
'xml_parser_create_ns' => 'XMLParser',
|
||||
// Broker
|
||||
'enchant_broker_init' => 'EnchantBroker',
|
||||
'enchant_broker_request_dict' => 'EnchantDictionary',
|
||||
'enchant_broker_request_pwl_dict' => 'EnchantDictionary',
|
||||
// OpenSSL
|
||||
'openssl_x509_read' => 'OpenSSLCertificate',
|
||||
'openssl_csr_sign' => 'OpenSSLCertificate',
|
||||
'openssl_csr_new' => 'OpenSSLCertificateSigningRequest',
|
||||
'openssl_pkey_new' => 'OpenSSLAsymmetricKey',
|
||||
// Shmop
|
||||
'shmop_open' => 'Shmop',
|
||||
// MessageQueue
|
||||
'msg_get_queue' => 'SysvMessageQueue',
|
||||
'sem_get' => 'SysvSemaphore',
|
||||
'shm_attach' => 'SysvSharedMemory',
|
||||
// Inflate Deflate
|
||||
'inflate_init' => 'InflateContext',
|
||||
'deflate_init' => 'DeflateContext',
|
||||
];
|
||||
public function __construct(ResourceReturnToObject $resourceReturnToObject)
|
||||
{
|
||||
$this->resourceReturnToObject = $resourceReturnToObject;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change is_resource() to instanceof Object', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$ch = curl_init();
|
||||
is_resource($ch);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$ch = curl_init();
|
||||
$ch instanceof \CurlHandle;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FuncCall::class, BooleanOr::class];
|
||||
}
|
||||
/**
|
||||
* @param FuncCall|BooleanOr $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
return $this->resourceReturnToObject->refactor($node, self::COLLECTION_FUNCTION_TO_RETURN_OBJECT);
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::PHP8_RESOURCE_TO_OBJECT;
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php81\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\Php80\NodeManipulator\ResourceReturnToObject;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.resource2object
|
||||
*
|
||||
* @see \Rector\Tests\Php81\Rector\FuncCall\Php81ResourceReturnToObjectRector\Php81ResourceReturnToObjectRectorTest
|
||||
*/
|
||||
final class Php81ResourceReturnToObjectRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php80\NodeManipulator\ResourceReturnToObject
|
||||
*/
|
||||
private $resourceReturnToObject;
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const COLLECTION_FUNCTION_TO_RETURN_OBJECT = [
|
||||
// finfo
|
||||
'finfo_open' => 'finfo',
|
||||
// ftp
|
||||
'ftp_connect' => 'FTP\\Connection',
|
||||
// imap_open
|
||||
'imap_open' => 'IMAP\\Connection',
|
||||
// pspell
|
||||
'pspell_config_create' => 'PSpell\\Config',
|
||||
'pspell_new_config' => 'PSpell\\Dictionary',
|
||||
// ldap
|
||||
'ldap_connect' => 'LDAP\\Connection',
|
||||
'ldap_read' => 'LDAP\\Result',
|
||||
'ldap_first_entry' => 'LDAP\\ResultEntry',
|
||||
'ldap_first_reference' => 'LDAP\\ResultEntry',
|
||||
'ldap_next_entry' => 'LDAP\\ResultEntry',
|
||||
'ldap_next_reference' => 'LDAP\\ResultEntry',
|
||||
// psql
|
||||
'pg_pconnect' => 'PgSql\\Connection',
|
||||
'pg_connect' => 'PgSql\\Connection',
|
||||
'pg_query' => 'PgSql\\Result',
|
||||
'pg_prepare' => 'PgSql\\Result',
|
||||
'pg_execute' => 'PgSql\\Result',
|
||||
'pg_lo_open' => 'PgSql\\Lob',
|
||||
];
|
||||
public function __construct(ResourceReturnToObject $resourceReturnToObject)
|
||||
{
|
||||
$this->resourceReturnToObject = $resourceReturnToObject;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change is_resource() to instanceof Object', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$f = finfo_open();
|
||||
is_resource($f);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$f = finfo_open();
|
||||
$f instanceof \finfo;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FuncCall::class, BooleanOr::class];
|
||||
}
|
||||
/**
|
||||
* @param FuncCall|BooleanOr $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
return $this->resourceReturnToObject->refactor($node, self::COLLECTION_FUNCTION_TO_RETURN_OBJECT);
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersionFeature::PHP81_RESOURCE_TO_OBJECT;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '499b272964a8b9dde2badaf872d053b3df17d162';
|
||||
public const PACKAGE_VERSION = 'b9ace5f53f1640ab947922957e8179b2b50ff2cd';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-09 00:14:17';
|
||||
public const RELEASE_DATE = '2023-07-08 23:44:58';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
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 ComposerAutoloaderInitdc7ab4b2735424de468bdf5bc4cfe531::getLoader();
|
||||
return ComposerAutoloaderInitd545642e01ffb8fcf674994e867c4119::getLoader();
|
||||
|
3
vendor/composer/autoload_classmap.php
vendored
3
vendor/composer/autoload_classmap.php
vendored
@ -2292,7 +2292,6 @@ return array(
|
||||
'Rector\\Php80\\NodeFactory\\NestedAttrGroupsFactory' => $baseDir . '/rules/Php80/NodeFactory/NestedAttrGroupsFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\StrStartsWithFuncCallFactory' => $baseDir . '/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php',
|
||||
'Rector\\Php80\\NodeManipulator\\AttributeGroupNamedArgumentManipulator' => $baseDir . '/rules/Php80/NodeManipulator/AttributeGroupNamedArgumentManipulator.php',
|
||||
'Rector\\Php80\\NodeManipulator\\ResourceReturnToObject' => $baseDir . '/rules/Php80/NodeManipulator/ResourceReturnToObject.php',
|
||||
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => $baseDir . '/rules/Php80/NodeResolver/ArgumentSorter.php',
|
||||
'Rector\\Php80\\NodeResolver\\RequireOptionalParamResolver' => $baseDir . '/rules/Php80/NodeResolver/RequireOptionalParamResolver.php',
|
||||
'Rector\\Php80\\NodeResolver\\SwitchExprsResolver' => $baseDir . '/rules/Php80/NodeResolver/SwitchExprsResolver.php',
|
||||
@ -2305,7 +2304,6 @@ return array(
|
||||
'Rector\\Php80\\Rector\\Class_\\ClassPropertyAssignToConstructorPromotionRector' => $baseDir . '/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php',
|
||||
'Rector\\Php80\\Rector\\Class_\\StringableForToStringRector' => $baseDir . '/rules/Php80/Rector/Class_/StringableForToStringRector.php',
|
||||
'Rector\\Php80\\Rector\\FuncCall\\ClassOnObjectRector' => $baseDir . '/rules/Php80/Rector/FuncCall/ClassOnObjectRector.php',
|
||||
'Rector\\Php80\\Rector\\FuncCall\\Php8ResourceReturnToObjectRector' => $baseDir . '/rules/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector.php',
|
||||
'Rector\\Php80\\Rector\\FunctionLike\\MixedTypeRector' => $baseDir . '/rules/Php80/Rector/FunctionLike/MixedTypeRector.php',
|
||||
'Rector\\Php80\\Rector\\Identical\\StrEndsWithRector' => $baseDir . '/rules/Php80/Rector/Identical/StrEndsWithRector.php',
|
||||
'Rector\\Php80\\Rector\\Identical\\StrStartsWithRector' => $baseDir . '/rules/Php80/Rector/Identical/StrStartsWithRector.php',
|
||||
@ -2333,7 +2331,6 @@ return array(
|
||||
'Rector\\Php81\\Rector\\Class_\\MyCLabsClassToEnumRector' => $baseDir . '/rules/Php81/Rector/Class_/MyCLabsClassToEnumRector.php',
|
||||
'Rector\\Php81\\Rector\\Class_\\SpatieEnumClassToEnumRector' => $baseDir . '/rules/Php81/Rector/Class_/SpatieEnumClassToEnumRector.php',
|
||||
'Rector\\Php81\\Rector\\FuncCall\\NullToStrictStringFuncCallArgRector' => $baseDir . '/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php',
|
||||
'Rector\\Php81\\Rector\\FuncCall\\Php81ResourceReturnToObjectRector' => $baseDir . '/rules/Php81/Rector/FuncCall/Php81ResourceReturnToObjectRector.php',
|
||||
'Rector\\Php81\\Rector\\FunctionLike\\IntersectionTypesRector' => $baseDir . '/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php',
|
||||
'Rector\\Php81\\Rector\\MethodCall\\MyCLabsMethodCallToEnumConstRector' => $baseDir . '/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php',
|
||||
'Rector\\Php81\\Rector\\MethodCall\\SpatieEnumMethodCallToEnumConstRector' => $baseDir . '/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php',
|
||||
|
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 ComposerAutoloaderInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
class ComposerAutoloaderInitd545642e01ffb8fcf674994e867c4119
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitdc7ab4b2735424de468bdf5bc4cfe531', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitd545642e01ffb8fcf674994e867c4119', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitdc7ab4b2735424de468bdf5bc4cfe531', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitd545642e01ffb8fcf674994e867c4119', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitd545642e01ffb8fcf674994e867c4119::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitd545642e01ffb8fcf674994e867c4119::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
11
vendor/composer/autoload_static.php
vendored
11
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
class ComposerStaticInitd545642e01ffb8fcf674994e867c4119
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2544,7 +2544,6 @@ class ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
'Rector\\Php80\\NodeFactory\\NestedAttrGroupsFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/NestedAttrGroupsFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\StrStartsWithFuncCallFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php',
|
||||
'Rector\\Php80\\NodeManipulator\\AttributeGroupNamedArgumentManipulator' => __DIR__ . '/../..' . '/rules/Php80/NodeManipulator/AttributeGroupNamedArgumentManipulator.php',
|
||||
'Rector\\Php80\\NodeManipulator\\ResourceReturnToObject' => __DIR__ . '/../..' . '/rules/Php80/NodeManipulator/ResourceReturnToObject.php',
|
||||
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/ArgumentSorter.php',
|
||||
'Rector\\Php80\\NodeResolver\\RequireOptionalParamResolver' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/RequireOptionalParamResolver.php',
|
||||
'Rector\\Php80\\NodeResolver\\SwitchExprsResolver' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/SwitchExprsResolver.php',
|
||||
@ -2557,7 +2556,6 @@ class ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
'Rector\\Php80\\Rector\\Class_\\ClassPropertyAssignToConstructorPromotionRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php',
|
||||
'Rector\\Php80\\Rector\\Class_\\StringableForToStringRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/Class_/StringableForToStringRector.php',
|
||||
'Rector\\Php80\\Rector\\FuncCall\\ClassOnObjectRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/FuncCall/ClassOnObjectRector.php',
|
||||
'Rector\\Php80\\Rector\\FuncCall\\Php8ResourceReturnToObjectRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector.php',
|
||||
'Rector\\Php80\\Rector\\FunctionLike\\MixedTypeRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/FunctionLike/MixedTypeRector.php',
|
||||
'Rector\\Php80\\Rector\\Identical\\StrEndsWithRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/Identical/StrEndsWithRector.php',
|
||||
'Rector\\Php80\\Rector\\Identical\\StrStartsWithRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/Identical/StrStartsWithRector.php',
|
||||
@ -2585,7 +2583,6 @@ class ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
'Rector\\Php81\\Rector\\Class_\\MyCLabsClassToEnumRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/Class_/MyCLabsClassToEnumRector.php',
|
||||
'Rector\\Php81\\Rector\\Class_\\SpatieEnumClassToEnumRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/Class_/SpatieEnumClassToEnumRector.php',
|
||||
'Rector\\Php81\\Rector\\FuncCall\\NullToStrictStringFuncCallArgRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php',
|
||||
'Rector\\Php81\\Rector\\FuncCall\\Php81ResourceReturnToObjectRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/FuncCall/Php81ResourceReturnToObjectRector.php',
|
||||
'Rector\\Php81\\Rector\\FunctionLike\\IntersectionTypesRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php',
|
||||
'Rector\\Php81\\Rector\\MethodCall\\MyCLabsMethodCallToEnumConstRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/MethodCall/MyCLabsMethodCallToEnumConstRector.php',
|
||||
'Rector\\Php81\\Rector\\MethodCall\\SpatieEnumMethodCallToEnumConstRector' => __DIR__ . '/../..' . '/rules/Php81/Rector/MethodCall/SpatieEnumMethodCallToEnumConstRector.php',
|
||||
@ -3080,9 +3077,9 @@ class ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitdc7ab4b2735424de468bdf5bc4cfe531::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitd545642e01ffb8fcf674994e867c4119::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitd545642e01ffb8fcf674994e867c4119::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitd545642e01ffb8fcf674994e867c4119::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user