Skip to content

Commit

Permalink
Fix ExplicitMethodCallOverMagicGetSetRector with a protected method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed May 4, 2023
1 parent 09b59ef commit 657ec2e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector\Fixture;

use Rector\Tests\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector\Source\ObjectWithMagicCallsProtectedMethods;

final class SkipProtectedMethods
{
public function run(ObjectWithMagicCallsProtectedMethods $object)
{
return $object->name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector\Source;

use Nette\SmartObject;

final class ObjectWithMagicCallsProtectedMethods
{
// adds magic __get() and __set() methods
use SmartObject;

private $name;

protected function getName()
{
return $this->name;
}

protected function setName(string $name)
{
$this->name = $name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch, Scope $scop

$methodReflection = $callerType->getMethod($possibleGetterMethodName, $scope);

if (! $methodReflection->isPublic()) {
continue;
}

$variant = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
$returnType = $variant->getReturnType();

Expand Down

0 comments on commit 657ec2e

Please sign in to comment.