Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster EnumCaseObjectType->describe() #3208

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class ObjectType implements TypeWithClassName, SubtractableType
/** @var array<string, list<EnumCaseObjectType>> */
private static array $enumCases = [];

/** @var array<int, string> */
private array $descriptions = [];

/** @api */
public function __construct(
private string $className,
Expand Down Expand Up @@ -475,6 +478,11 @@ private function checkSubclassAcceptability(string $thatClass): AcceptsResult

public function describe(VerbosityLevel $level): string
{
$levelValue = $level->getLevelValue();
if (array_key_exists($levelValue, $this->descriptions)) {
return $this->descriptions[$levelValue];
}

$preciseNameCallback = function (): string {
$reflectionProvider = ReflectionProviderStaticAccessor::getInstance();
if (!$reflectionProvider->hasClass($this->className)) {
Expand All @@ -493,7 +501,7 @@ public function describe(VerbosityLevel $level): string
return $description;
};

return $level->handle(
return $this->descriptions[$levelValue] = $level->handle(
$preciseNameCallback,
$preciseNameCallback,
$preciseWithSubtracted,
Expand Down
Loading