-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1256 from herndlm/trait-circular-ref3
Detection of circular references in constant, method and property getters
- Loading branch information
Showing
5 changed files
with
226 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Roave\BetterReflection\Reflection\Support; | ||
|
||
use Roave\BetterReflection\Reflection\Exception\CircularReference; | ||
|
||
use function array_key_exists; | ||
|
||
/** @internal */ | ||
final class AlreadyVisitedClasses | ||
{ | ||
/** @param array<class-string, null> $classNames */ | ||
private function __construct(private array $classNames) | ||
{ | ||
} | ||
|
||
public static function createEmpty(): self | ||
{ | ||
return new self([]); | ||
} | ||
|
||
/** @param class-string $className */ | ||
public function push(string $className): void | ||
{ | ||
if (array_key_exists($className, $this->classNames)) { | ||
throw CircularReference::fromClassName($className); | ||
} | ||
|
||
$this->classNames[$className] = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Roave\BetterReflectionTest\Fixture\InvalidTraitUses; | ||
|
||
trait TraitUsesSelf | ||
{ | ||
use TraitUsesSelf; | ||
} | ||
|
||
trait Trait1 | ||
{ | ||
use Trait2; | ||
} | ||
trait Trait2 | ||
{ | ||
use Trait1; | ||
} | ||
trait Trait3 | ||
{ | ||
use Trait2; | ||
} | ||
|
||
class Class1 | ||
{ | ||
use TraitUsesSelf; | ||
} | ||
|
||
class Class2 | ||
{ | ||
use Trait1; | ||
} |
Oops, something went wrong.