-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php80] Add Php8ResourceReturnToObjectRector (#1068)
* [Php80] Add Php8ResourceToObjectRector * [ci-review] Rector Rectify * [ci-review] Rector Rectify * apply with check is_resource * [ci-review] Rector Rectify * ensure assign var is the arg resource * applied for curl_init() return * phpstan * register curl_multi_init and curl_share_init * skip double check * ensure variable compare equal on double check * phpstan * rename to Php8ResourceReturnToObjectRector * rename test * rename service * check via NodeTypeResolver->getType() * [ci-review] Rector Rectify * check double check specifically for BooleanOr * handle double check * skip complex condition * skip complex condition * refactoring * refactoring * refactoring * [ci-review] Rector Rectify * handle flip check * phpstan * handle combined with ChangeOrIfReturnToEarlyReturnRector * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * typo fix * add socket_create example * more list for socket * remove comment * check different instanceof check * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * add failing fixture for different condition * fix * phpstan * phpstan * register xmlwriter_open_memory * add XMLParser * more to the list * add example for openssl * example for shmop_open * add example for msg_get_queue * add example for inflate_init * add example for enchant_broker_init * register GD functions * add example for imagecreate Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
7b848a7
commit 6bcdc92
Showing
29 changed files
with
1,121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...hp80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/different_condition.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCondition | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
is_resource($ch) || rand(0, 1); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCondition | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle || rand(0, 1); | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...p80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/different_instanceof.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DifferentInstanceof | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
is_resource($ch) || $ch instanceof \stdClass; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DifferentInstanceof | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle || $ch instanceof \stdClass; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...r/FuncCall/Php8ResourceReturnToObjectRector/Fixture/different_instanceof_variable.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DifferentInstanceofVariable | ||
{ | ||
public function run($abc) | ||
{ | ||
$ch = curl_init(); | ||
is_resource($ch) || $abc instanceof \stdClass; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DifferentInstanceofVariable | ||
{ | ||
public function run($abc) | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle || $abc instanceof \stdClass; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...tests/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/double_check.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCheck | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
is_resource($ch) || $ch instanceof \CurlHandle; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCheck | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
.../Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/double_check_flip.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCheckFlip | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle || is_resource($ch); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCheckFlip | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...r/FuncCall/Php8ResourceReturnToObjectRector/Fixture/double_check_with_parenthesis.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCheckWithParenthesis | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
file_exists($fileName) && (is_resource($ch) || $ch instanceof \CurlHandle) && is_dir($dir); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class DoubleCheckWithParenthesis | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
file_exists($fileName) && ($ch instanceof \CurlHandle) && is_dir($dir); | ||
} | ||
} | ||
|
||
?> |
12 changes: 12 additions & 0 deletions
12
...0/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/skip_complex_condition.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SkipComplexCondition | ||
{ | ||
public function run(string $fileName, string $dir) | ||
{ | ||
$ch = curl_init(); | ||
file_exists($fileName) && is_resource($ch) || $ch instanceof \CurlHandle && is_dir($dir); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...hp80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/some_ msg_get_queue.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeMsgGetQueue | ||
{ | ||
public function run() | ||
{ | ||
$seg = msg_get_queue($MSGKey) ; | ||
is_resource($seg); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeMsgGetQueue | ||
{ | ||
public function run() | ||
{ | ||
$seg = msg_get_queue($MSGKey) ; | ||
$seg instanceof \SysvMessageQueue; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...sts/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/some_curl_init.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeCurlInit | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
is_resource($ch); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeCurlInit | ||
{ | ||
public function run() | ||
{ | ||
$ch = curl_init(); | ||
$ch instanceof \CurlHandle; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/some_enhance_broker_init.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeEnhanceBrokerInit | ||
{ | ||
public function run() | ||
{ | ||
$ch = enchant_broker_init(); | ||
is_resource($ch); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeEnhanceBrokerInit | ||
{ | ||
public function run() | ||
{ | ||
$ch = enchant_broker_init(); | ||
$ch instanceof \EnchantBroker; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...s/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/some_imagecreate.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeImageCreate | ||
{ | ||
public function run() | ||
{ | ||
$gd = imagecreate(1, 2); | ||
is_resource($gd); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeImageCreate | ||
{ | ||
public function run() | ||
{ | ||
$gd = imagecreate(1, 2); | ||
$gd instanceof \GdImage; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
.../Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector/Fixture/some_inflate_init.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeInflateInit | ||
{ | ||
public function run() | ||
{ | ||
$context = inflate_init(ZLIB_ENCODING_DEFLATE); | ||
is_resource($context); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector\Fixture; | ||
|
||
final class SomeInflateInit | ||
{ | ||
public function run() | ||
{ | ||
$context = inflate_init(ZLIB_ENCODING_DEFLATE); | ||
$context instanceof \InflateContext; | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.