Skip to content

Commit

Permalink
[CodeQuality] Skip stdClass in IssetOnPropertyObjectToPropertyExistsR…
Browse files Browse the repository at this point in the history
…ector, as always nested (#3166)
  • Loading branch information
TomasVotruba committed Dec 7, 2022
1 parent 045ada5 commit 7636b88
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.

This file was deleted.

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

namespace Rector\Tests\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector\Fixture;

use stdClass;

final class SkipDirectStdClass
{
public function x(stdClass $value) {
isset($value->property);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector\Fixture;

final class SkipStdClassFromJson
{
public function run(string $contents) {
$result = json_decode($contents);
return isset($result->key->value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public function refactor(Node $node): ?Node
$propertyFetchVarType = $this->getType($issetVar->var);

if ($propertyFetchVarType instanceof TypeWithClassName) {
if ($propertyFetchVarType->getClassName() === 'stdClass') {
continue;
}

if (! $this->reflectionProvider->hasClass($propertyFetchVarType->getClassName())) {
continue;
}
Expand All @@ -119,12 +123,6 @@ public function refactor(Node $node): ?Node
} else {
$newNodes[] = $this->createNotIdenticalToNull($issetVar);
}
} else {
$newNodes[] = $this->replaceToPropertyExistsWithNullCheck(
$issetVar->var,
$propertyFetchName,
$issetVar
);
}
}

Expand Down

0 comments on commit 7636b88

Please sign in to comment.