-
-
Notifications
You must be signed in to change notification settings - Fork 429
[Php81] added RemoveReflectionSetAccessibleCallsRector
#7085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Php81] added RemoveReflectionSetAccessibleCallsRector
#7085
Conversation
4087338 to
2d84438
Compare
This comment was marked as resolved.
This comment was marked as resolved.
RemoveDeprecatedReflectionSetAccessibleCallsRectorRemoveReflectionSetAccessibleCallsRector
|
You may need to install gpatch and register to path, see troubleshooting note https://github.com/symplify/vendor-patches/?tab=readme-ov-file#troubleshooting |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the rule. Targeting 8.1 would be better, as we add rules as soon the change appears in PHP. |
|
@TomasVotruba there is no "deprecation" warning on php 8.1, it just have no effect, see https://3v4l.org/ukI3N#v8.1.33 For note: downgrade to php 8.0 rule is needed for it, to add: if (PHP_VERSION_ID <=80100) {
$r->setAccessible(true);
}to avoid error on downgrade upgraded code, see https://3v4l.org/ukI3N#v8.0.30 |
2d84438 to
84deedb
Compare
|
@samsonasik Exactly, it's no longer required. That's why it should be in 8.1 as a dead code |
@TomasVotruba That's done.
@samsonasik That's correct. However, to have the calls in >=8.1 is useless either way |
84deedb to
5b59464
Compare
|
We have setAccessible call in rector-src code:
If https://github.com/rectorphp/rector-downgrade-php/tree/main/rules/DowngradePhp80 Then register at https://github.com/rectorphp/rector-downgrade-php/blob/main/config/set/downgrade-php80.php |
@samsonasik, I never looked into downgrade rules. I assume it must also cover situations where no upgrade rule was run, and where the |
|
I think we have this covered in PHP 8.1 downgrade set: I made sure it works 👍 rectorphp/rector-downgrade-php#155 |
RemoveReflectionSetAccessibleCallsRectorRemoveReflectionSetAccessibleCallsRector
|
@TomasVotruba thank you for verify @NickSdot could you try run: then ensure this line removed
then, we can merge to see if it can be downgraded correctly, thank you. |
|
@TomasVotruba the downgrade rule only handle |
@samsonasik, yep, that works. There are more than one call of it. Subject: [PATCH] chore: ran rector
---
Index: src/Util/Reflection/PrivatesAccessor.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Util/Reflection/PrivatesAccessor.php b/src/Util/Reflection/PrivatesAccessor.php
--- a/src/Util/Reflection/PrivatesAccessor.php (revision 5b59464b0a17c34b1f492898660e25cedb02841b)
+++ b/src/Util/Reflection/PrivatesAccessor.php (date 1753259388951)
@@ -47,7 +47,6 @@
public function getPrivateProperty(object $object, string $propertyName): mixed
{
$reflectionProperty = $this->resolvePropertyReflection($object, $propertyName);
- $reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($object);
}
@@ -55,17 +54,13 @@
public function setPrivateProperty(object $object, string $propertyName, mixed $value): void
{
$reflectionProperty = $this->resolvePropertyReflection($object, $propertyName);
- $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($object, $value);
}
private function createAccessibleMethodReflection(object $object, string $methodName): ReflectionMethod
{
- $reflectionMethod = new ReflectionMethod($object, $methodName);
- $reflectionMethod->setAccessible(true);
-
- return $reflectionMethod;
+ return new ReflectionMethod($object, $methodName);
}
private function resolvePropertyReflection(object $object, string $propertyName): ReflectionPropertyThere are also some formatting changes that Subject: [PATCH] chore: ran rector
---
Index: rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php b/rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php
--- a/rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php (revision 5b59464b0a17c34b1f492898660e25cedb02841b)
+++ b/rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php (date 1753259379572)
@@ -47,8 +47,8 @@
return null;
}
- if ($this->isObjectType($methodCall->var, new ObjectType('ReflectionProperty')) === true
- || $this->isObjectType($methodCall->var, new ObjectType('ReflectionMethod')) === true
+ if ($this->isObjectType($methodCall->var, new ObjectType('ReflectionProperty'))
+ || $this->isObjectType($methodCall->var, new ObjectType('ReflectionMethod'))
) {
return NodeVisitor::REMOVE_NODE;
}
Index: rules-tests/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector/RemoveReflectionSetAccessibleCallsRectorTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/rules-tests/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector/RemoveReflectionSetAccessibleCallsRectorTest.php b/rules-tests/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector/RemoveReflectionSetAccessibleCallsRectorTest.php
--- a/rules-tests/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector/RemoveReflectionSetAccessibleCallsRectorTest.php (revision 5b59464b0a17c34b1f492898660e25cedb02841b)
+++ b/rules-tests/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector/RemoveReflectionSetAccessibleCallsRectorTest.php (date 1753259374024)
@@ -4,6 +4,7 @@
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector;
+use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
@@ -16,9 +17,9 @@
}
/**
- * @return \Iterator<array<string>>
+ * @return Iterator<array<string>>
*/
- public static function provideData(): \Iterator
+ public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
} |
|
@NickSdot thank you, I created PR to allow downgrade ReflectionMethod as well: |
|
Two questions:
|
|
@samsonasik committed and pushed. FYI: |
|
It seems you need to rebase latest main |
| $reflectionMethod->setAccessible(true); | ||
|
|
||
| return $reflectionMethod; | ||
| return new ReflectionMethod($object, $methodName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the downgrade rule seems not handling on return yet, only Expression, I will look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: DowngradeSetAccessibleReflectionPropertyRector has "Property" in the name. Your last PR rectorphp/rector-downgrade-php#296 added handling for methods. Just pointing it out in case that's relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that isNames() for :)
if (! $this->isNames($new->class, ['ReflectionProperty', 'ReflectionMethod'])) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created PR to handle on direct return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just meant that the rule name now no longer exactly fits to what the rule does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that can be refactored next (if needed :) ), but we need to ensure downgrade working first :)
|
Okay, preparation is done for our use cases :), @TomasVotruba let's merge. Thank you @NickSdot |
|
That was fun! 🤝 |
|
It seems downgraded correctly rectorphp/rector@415cc1a#diff-aa4acc8abf2aa549804bc88f2b13eb203d8a18dd8f8a6e9db9289038a4ab1a2d On |
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
As of PHP 8.1.0, calling
Reflection*::setAccessible()has no effect; all properties are accessible by default. Currently, there is a RFC which proposes to issue a deprecation warning starting with Php 8.5.Note:
I added it to the 8.5 rules, because it will likely be decprecated by then. Alternatively, we could add it to the 8.1 rules. Let me know if you think this would be more sensible.