Skip to content

Commit

Permalink
[CodeQuality] Skip pull property from inner class on CompleteDynamicP…
Browse files Browse the repository at this point in the history
…ropertiesRector (#4561)

* [CodeQuality] Skip pull property from inner class on CompleteDynamicPropertiesRector

* Fix

* clean up

* clean up

* clean up

* skip pull from differnt class
  • Loading branch information
samsonasik committed Jul 20, 2023
1 parent ef6aa9e commit 1411c04
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,14 @@ private function resolveClassOrInterfaceScope(
$classReflection = $this->reflectionProvider->getClass($className);
}

$context = $this->privatesAccessor->getPrivateProperty($mutatingScope, 'context');

try {
$this->privatesAccessor->setPrivateProperty($context, 'classReflection', $classReflection);
return $mutatingScope->enterClass($classReflection);
} catch (\PHPStan\ShouldNotHappenException) {
$this->privatesAccessor->setPrivateProperty($context, 'classReflection', null);
}

$context = $this->privatesAccessor->getPrivateProperty($mutatingScope, 'context');
$this->privatesAccessor->setPrivateProperty($context, 'classReflection', null);

return $mutatingScope->enterClass($classReflection);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector\Fixture;

final class SkipInnerClass
{
public function run()
{
$box = new class () {
public $logged;

public function hold(string $value)
{
$this->logged = $value;
}
};

echo $box->logged;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector\Source\DifferentClass;

class SkipPullFromDifferentClass
{
public function run()
{
$obj = new DifferentClass();
echo $obj->property;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector\Source;

class DifferentClass
{
public $property = 'some value';
}

0 comments on commit 1411c04

Please sign in to comment.