<commit_before><?php

declare(strict_types=1);

namespace Rector\Core\Rector\AbstractRector;

use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use Rector\CodingStyle\Naming\ClassNaming;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
 * This could be part of @see AbstractRector, but decopuling to trait
 * makes clear what code has 1 purpose.
 */
trait NameResolverTrait
{
    /**
     * @var NodeNameResolver
     */
    private $nodeNameResolver;

    /**
     * @var ClassNaming
     */
    private $classNaming;

    /**
     * @required
     */
    public function autowireNameResolverTrait(NodeNameResolver $nodeNameResolver, ClassNaming $classNaming): void
    {
        $this->nodeNameResolver = $nodeNameResolver;
        $this->classNaming = $classNaming;
    }

    public function isName(Node $node, string $name): bool
    {
        return $this->nodeNameResolver->isName($node, $name);
    }

    public function areNamesEqual(Node $firstNode, Node $secondNode): bool
    {
        return $this->nodeNameResolver->areNamesEqual($firstNode, $secondNode);
    }

    /**
     * @param string[] $names
     */
    public function isNames(Node $node, array $names): bool
    {
        return $this->nodeNameResolver->isNames($node, $names);
    }

    public function getName(Node $node): ?string
    {
        return $this->nodeNameResolver->getName($node);
    }

    /**
     * @param string|Name|Identifier $name
     */
    protected function getShortName($name): string
    {
        return $this->classNaming->getShortName($name);
    }

    protected function isLocalPropertyFetchNamed(Node $node, string $name): bool
    {
        if (! $node instanceof PropertyFetch) {
            return false;
        }

        if (! $this->isName($node->var, 'this')) {
            return false;
        }

        return $this->isName($node->name, $name);
    }

    protected function isLocalMethodCallNamed(Node $node, string $name): bool
    {
        if (! $node instanceof MethodCall) {
            return false;
        }

        if ($node->var instanceof StaticCall) {
            return false;
        }

        if ($node->var instanceof MethodCall) {
            return false;
        }

        if (! $this->isName($node->var, 'this')) {
            return false;
        }

        return $this->isName($node->name, $name);
    }

    protected function isLocalMethodCallsNamed(Node $node, array $names): bool
    {
        foreach ($names as $name) {
            if ($this->isLocalMethodCallNamed($node, $name)) {
                return true;
            }
        }

        return false;
    }

    protected function isFuncCallName(Node $node, string $name): bool
    {
        if (! $node instanceof FuncCall) {
            return false;
        }

        return $this->isName($node, $name);
    }

    /**
     * Detects "SomeClass::class"
     */
    protected function isClassConstReference(Node $node, string $className): bool
    {
        if (! $node instanceof ClassConstFetch) {
            return false;
        }

        if (! $this->isName($node->name, 'class')) {
            return false;
        }

        return $this->isName($node->class, $className);
    }

    protected function isStaticCallNamed(Node $node, string $className, string $methodName): bool
    {
        if (! $node instanceof StaticCall) {
            return false;
        }

        if (! $this->isName($node->class, $className)) {
            return false;
        }

        return $this->isName($node->name, $methodName);
    }

    /**
     * @param string[] $methodNames
     */
    protected function isStaticCallsNamed(Node $node, string $className, array $methodNames): bool
    {
        foreach ($methodNames as $methodName) {
            if ($this->isStaticCallNamed($node, $className, $methodName)) {
                return true;
            }
        }

        return false;
    }

    protected function isMethodCall(Node $node, string $variableName, string $methodName): bool
    {
        if (! $node instanceof MethodCall) {
            return false;
        }

        if (! $this->isName($node->var, $variableName)) {
            return false;
        }

        return $this->isName($node->name, $methodName);
    }

    protected function isVariableName(?Node $node, string $name): bool
    {
        if (! $node instanceof Variable) {
            return false;
        }

        return $this->isName($node, $name);
    }

    protected function isInClassNamed(Node $node, string $desiredClassName): bool
    {
        return $node->getAttribute(AttributeKey::CLASS_NAME) === $desiredClassName;
    }<commit_msg>fix get name or static call<commit_after><?php

declare(strict_types=1);

namespace Rector\Core\Rector\AbstractRector;

use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use Rector\CodingStyle\Naming\ClassNaming;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
 * This could be part of @see AbstractRector, but decopuling to trait
 * makes clear what code has 1 purpose.
 */
trait NameResolverTrait
{
    /**
     * @var NodeNameResolver
     */
    private $nodeNameResolver;

    /**
     * @var ClassNaming
     */
    private $classNaming;

    /**
     * @required
     */
    public function autowireNameResolverTrait(NodeNameResolver $nodeNameResolver, ClassNaming $classNaming): void
    {
        $this->nodeNameResolver = $nodeNameResolver;
        $this->classNaming = $classNaming;
    }

    public function isName(Node $node, string $name): bool
    {
        return $this->nodeNameResolver->isName($node, $name);
    }

    public function areNamesEqual(Node $firstNode, Node $secondNode): bool
    {
        return $this->nodeNameResolver->areNamesEqual($firstNode, $secondNode);
    }

    /**
     * @param string[] $names
     */
    public function isNames(Node $node, array $names): bool
    {
        return $this->nodeNameResolver->isNames($node, $names);
    }

    public function getName(Node $node): ?string
    {
        return $this->nodeNameResolver->getName($node);
    }

    /**
     * @param string|Name|Identifier $name
     */
    protected function getShortName($name): string
    {
        return $this->classNaming->getShortName($name);
    }

    protected function isLocalPropertyFetchNamed(Node $node, string $name): bool
    {
        if (! $node instanceof PropertyFetch) {
            return false;
        }

        if (! $this->isName($node->var, 'this')) {
            return false;
        }

        return $this->isName($node->name, $name);
    }

    protected function isLocalMethodCallNamed(Node $node, string $name): bool
    {
        if (! $node instanceof MethodCall) {
            return false;
        }

        if ($node->var instanceof StaticCall) {
            return false;
        }

        if ($node->var instanceof MethodCall) {
            return false;
        }

        if (! $this->isName($node->var, 'this')) {
            return false;
        }

        return $this->isName($node->name, $name);
    }

    protected function isLocalMethodCallsNamed(Node $node, array $names): bool
    {
        foreach ($names as $name) {
            if ($this->isLocalMethodCallNamed($node, $name)) {
                return true;
            }
        }

        return false;
    }

    protected function isFuncCallName(Node $node, string $name): bool
    {
        if (! $node instanceof FuncCall) {
            return false;
        }

        return $this->isName($node, $name);
    }

    /**
     * Detects "SomeClass::class"
     */
    protected function isClassConstReference(Node $node, string $className): bool
    {
        if (! $node instanceof ClassConstFetch) {
            return false;
        }

        if (! $this->isName($node->name, 'class')) {
            return false;
        }

        return $this->isName($node->class, $className);
    }

    protected function isStaticCallNamed(Node $node, string $className, string $methodName): bool
    {
        if (! $node instanceof StaticCall) {
            return false;
        }

        if (! $this->isName($node->class, $className)) {
            return false;
        }

        return $this->isName($node->name, $methodName);
    }

    /**
     * @param string[] $methodNames
     */
    protected function isStaticCallsNamed(Node $node, string $className, array $methodNames): bool
    {
        foreach ($methodNames as $methodName) {
            if ($this->isStaticCallNamed($node, $className, $methodName)) {
                return true;
            }
        }

        return false;
    }

    protected function isMethodCall(Node $node, string $variableName, string $methodName): bool
    {
        if (! $node instanceof MethodCall) {
            return false;
        }

        if ($node->var instanceof MethodCall) {
            return false;
        }

        if ($node->var instanceof StaticCall) {
            return false;
        }

        if (! $this->isName($node->var, $variableName)) {
            return false;
        }

        return $this->isName($node->name, $methodName);
    }

    protected function isVariableName(?Node $node, string $name): bool
    {
        if (! $node instanceof Variable) {
            return false;
        }

        return $this->isName($node, $name);
    }

    protected function isInClassNamed(Node $node, string $desiredClassName): bool
    {
        return $node->getAttribute(AttributeKey::CLASS_NAME) === $desiredClassName;
    }
{'fraction_non_alphanumeric': 0.1210077365602063, 'fraction_numerical': 0.00039674667724657806, 'mean_word_length': 2.2715768981181053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3825708', 'n_tokens_mistral': 2917, 'n_tokens_neox': 2834, 'n_words': 665}