Skip to content

Commit

Permalink
[NodeNameResolver] Set return false on node is MethodCall/StaticCall …
Browse files Browse the repository at this point in the history
…on NodeNameResolver::isName() (#5981)

Co-authored-by: kaizen-ci <info@kaizen-ci.org>
  • Loading branch information
samsonasik and kaizen-ci authored Mar 24, 2021
1 parent 45f6570 commit d266e69
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/NodeNameResolver/NodeNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ public function isNames(Node $node, array $names): bool
*/
public function isName($node, string $name): bool
{
if ($node instanceof MethodCall || $node instanceof StaticCall) {
$message = sprintf(
'Name called on "%s" is not possible. Use $this->getName($node->name) instead',
get_class($node)
);
throw new ShouldNotHappenException($message);
if ($node instanceof MethodCall) {
return false;
}
if ($node instanceof StaticCall) {
return false;
}

$nodes = is_array($node) ? $node : [$node];

foreach ($nodes as $node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

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

final class Carbon
{
public $timestamp;

public static function now()
{
return new static();
}
}

class SkipStaticReturnObject
{
public function getCurrentTimestamp()
{
return Carbon::now()->timestamp;
}
}

0 comments on commit d266e69

Please sign in to comment.