Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 6, 2024
1 parent 8db44af commit df7a8da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/Enum/StaticAccessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\SwissKnife\Enum;

final class StaticAccessor
{
/**
* @var string
*/
public const STATIC = 'static';

/**
* @var string
*/
public const SELF = 'self';
}
8 changes: 5 additions & 3 deletions src/PhpParser/NodeVisitor/FindClassConstFetchNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use Rector\SwissKnife\Contract\ClassConstantFetchInterface;
use Rector\SwissKnife\Enum\StaticAccessor;
use Rector\SwissKnife\Exception\NotImplementedYetException;
use Rector\SwissKnife\Exception\ShouldNotHappenException;
use Rector\SwissKnife\ValueObject\ClassConstantFetch\CurrentClassConstantFetch;
Expand Down Expand Up @@ -71,7 +72,8 @@ public function enterNode(Node $node): Node|int|null
if ($constantName === 'class') {
return null;
}
if ($className === 'self') {

if ($className === StaticAccessor::SELF) {
Assert::isInstanceOf($this->currentClass, Class_::class);

$currentClassName = $this->getClassName();
Expand All @@ -90,7 +92,7 @@ public function enterNode(Node $node): Node|int|null
return $node;
}

if ($className === 'static') {
if ($className === StaticAccessor::STATIC) {
Assert::isInstanceOf($this->currentClass, Class_::class);

$currentClassName = $this->getClassName();
Expand Down Expand Up @@ -163,7 +165,7 @@ private function isCurrentClassConstant(Class_ $currentClass, string $constantNa
private function getClassName(): string
{
if (! $this->currentClass instanceof Class_) {
throw new ShouldNotHappenException();
throw new ShouldNotHappenException('Class_ node is missing');
}

$namespaceName = $this->currentClass->namespacedName;
Expand Down

0 comments on commit df7a8da

Please sign in to comment.