Skip to content

Commit

Permalink
[Php81] Skip ArrayDimFetch from ArrayObject in Assign var on ReadOnly…
Browse files Browse the repository at this point in the history
…PropertyRector (#2363)

* [Php81] Skip ArrayDimFetch from ArrayObject in Assign var on ReadOnlyPropertyRector

* Fixed 🎉

* eol
  • Loading branch information
samsonasik committed May 26, 2022
1 parent 66dbb1e commit 3da22b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/ReadWrite/NodeAnalyzer/ReadWritePropertyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public function isRead(PropertyFetch | StaticPropertyFetch $node): bool
return ! $this->assignManipulator->isLeftPartOfAssign($node);
}

if (! $this->isArrayDimFetchInImpureFunction($parent, $node)) {
return ! $this->assignManipulator->isLeftPartOfAssign($node);
if ($this->assignManipulator->isLeftPartOfAssign($parent)) {
return false;
}

return false;
return ! $this->isArrayDimFetchInImpureFunction($parent, $node);
}

private function isArrayDimFetchInImpureFunction(ArrayDimFetch $arrayDimFetch, Node $node): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;

use ArrayObject;

final class SkipArrayDimFetchFromArrayObjectInAssignVar
{
private ArrayObject $array;

public function __construct()
{
$this->array = new ArrayObject();
}

public function getOrSet(int|string $key, mixed $value = null): mixed
{
return $this->array[$key] ??= $value;
}
}

0 comments on commit 3da22b0

Please sign in to comment.