Skip to content
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

[DowngradePhp80] Allow nullable ReflectionProperty as well on DowngradeReflectionGetAttributesRector #203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\MethodCall\DowngradeReflectionGetAttributesRector\Fixture;

class UseNullableReflectionProperty
{
public function run(?\ReflectionProperty $reflectionProperty)
{
if ($reflectionProperty->getAttributes('SomeAttribute')[0] ?? null) {
return true;
}

return false;
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\MethodCall\DowngradeReflectionGetAttributesRector\Fixture;

class UseNullableReflectionProperty
{
public function run(?\ReflectionProperty $reflectionProperty)
{
if ((method_exists($reflectionProperty, 'getAttributes') ? $reflectionProperty->getAttributes('SomeAttribute') : [])[0] ?? null) {
return true;
}

return false;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\MethodCall\DowngradeReflectionGetAttributesRector\Fixture;

class UseReflectionProperty
{
public function run(\ReflectionProperty $reflectionProperty)
{
if ($reflectionProperty->getAttributes()) {
return true;
}

return false;
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\MethodCall\DowngradeReflectionGetAttributesRector\Fixture;

class UseReflectionProperty
{
public function run(\ReflectionProperty $reflectionProperty)
{
if (method_exists($reflectionProperty, 'getAttributes') ? $reflectionProperty->getAttributes() : []) {
return true;
}

return false;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function refactor(Node $node): Ternary|null|int
if (
! $this->isObjectType($node->var, new ObjectType('Reflector'))
&& ! $this->isObjectType($node->var, new ObjectType('ReflectionClass'))
&& ! $this->isObjectType($node->var, new ObjectType('ReflectionProperty'))
Comment on lines 85 to +86
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba the real solution is probably patch the NodeTypeResolver::isMatchingUnionType() instead, so it can work on its object or the child for nullable.

) {
return null;
}
Expand Down
Loading