-
Notifications
You must be signed in to change notification settings - Fork 574
Introduce ClosureType::isStaticClosure()
#5699
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
base: 2.1.x
Are you sure you want to change the base?
Changes from 1 commit
ebd8f8a
eb5202f
438e5ba
cd04085
792cece
86e8a15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,8 @@ class ClosureType implements TypeWithClassName, CallableParametersAcceptor | |
|
|
||
| private Assertions $assertions; | ||
|
|
||
| private TrinaryLogic $isStatic; | ||
|
|
||
| /** | ||
| * @api | ||
| * @param list<ParameterReflection>|null $parameters | ||
|
|
@@ -112,6 +114,7 @@ public function __construct( | |
| ?TrinaryLogic $acceptsNamedArguments = null, | ||
| ?TrinaryLogic $mustUseReturnValue = null, | ||
| ?Assertions $assertions = null, | ||
| ?TrinaryLogic $isStatic = null, | ||
| ) | ||
| { | ||
| if ($acceptsNamedArguments === null) { | ||
|
|
@@ -132,6 +135,7 @@ public function __construct( | |
| $this->callSiteVarianceMap = $callSiteVarianceMap ?? TemplateTypeVarianceMap::createEmpty(); | ||
| $this->impurePoints = $impurePoints ?? [new SimpleImpurePoint('functionCall', 'call to an unknown Closure', false)]; | ||
| $this->assertions = $assertions ?? Assertions::createEmpty(); | ||
| $this->isStatic = $isStatic ?? TrinaryLogic::createMaybe(); | ||
| } | ||
|
|
||
| public function getAsserts(): Assertions | ||
|
|
@@ -268,7 +272,8 @@ public function equals(Type $type): bool | |
| } | ||
|
|
||
| return $this->describe(VerbosityLevel::precise()) === $type->describe(VerbosityLevel::precise()) | ||
| && $this->isPure()->equals($type->isPure()); | ||
| && $this->isPure()->equals($type->isPure()) | ||
| && $this->isStatic->equals($type->isStatic); | ||
| } | ||
|
|
||
| public function describe(VerbosityLevel $level): string | ||
|
|
@@ -306,6 +311,72 @@ function (): string { | |
|
|
||
| return $printer->print($selfWithoutParameterNames->toPhpDocNode()); | ||
| }, | ||
| function (): string { | ||
| $prefix = $this->isStatic->yes() ? 'static ' : ''; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefix should be with a |
||
| if ($this->isCommonCallable) { | ||
| $name = $this->isPure()->yes() ? 'pure-Closure' : 'Closure'; | ||
| return $prefix . $name; | ||
| } | ||
|
|
||
| $printer = new Printer(); | ||
| $selfWithoutParameterNames = new self( | ||
| array_map(static fn (ParameterReflection $p): ParameterReflection => new DummyParameter( | ||
| '', | ||
| $p->getType(), | ||
| optional: $p->isOptional() && !$p->isVariadic(), | ||
| passedByReference: PassedByReference::createNo(), | ||
| variadic: $p->isVariadic(), | ||
| defaultValue: $p->getDefaultValue(), | ||
| ), $this->parameters), | ||
| $this->returnType, | ||
| $this->variadic, | ||
| $this->templateTypeMap, | ||
| $this->resolvedTemplateTypeMap, | ||
| $this->callSiteVarianceMap, | ||
| $this->templateTags, | ||
| $this->throwPoints, | ||
| $this->impurePoints, | ||
| $this->invalidateExpressions, | ||
| $this->usedVariables, | ||
| $this->acceptsNamedArguments, | ||
| $this->mustUseReturnValue, | ||
| ); | ||
|
|
||
| return $prefix . $printer->print($selfWithoutParameterNames->toPhpDocNode()); | ||
| }, | ||
| function (): string { | ||
| $prefix = !$this->isStatic->maybe() ? ($this->isStatic->yes() ? 'static ' : 'non-static ') : ''; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no reason to use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both commits are pushed. Here's a summary of the changes: Commit 1: Revert
Commit 2: Use hyphen prefix and extract helper method
|
||
| if ($this->isCommonCallable) { | ||
| $name = $this->isPure()->yes() ? 'pure-Closure' : 'Closure'; | ||
| return $prefix . $name; | ||
| } | ||
|
|
||
| $printer = new Printer(); | ||
| $selfWithoutParameterNames = new self( | ||
| array_map(static fn (ParameterReflection $p): ParameterReflection => new DummyParameter( | ||
| '', | ||
| $p->getType(), | ||
| optional: $p->isOptional() && !$p->isVariadic(), | ||
| passedByReference: PassedByReference::createNo(), | ||
| variadic: $p->isVariadic(), | ||
| defaultValue: $p->getDefaultValue(), | ||
| ), $this->parameters), | ||
| $this->returnType, | ||
| $this->variadic, | ||
| $this->templateTypeMap, | ||
| $this->resolvedTemplateTypeMap, | ||
| $this->callSiteVarianceMap, | ||
| $this->templateTags, | ||
| $this->throwPoints, | ||
| $this->impurePoints, | ||
| $this->invalidateExpressions, | ||
| $this->usedVariables, | ||
| $this->acceptsNamedArguments, | ||
| $this->mustUseReturnValue, | ||
| ); | ||
|
|
||
| return $prefix . $printer->print($selfWithoutParameterNames->toPhpDocNode()); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -496,6 +567,11 @@ public function mustUseReturnValue(): TrinaryLogic | |
| return $this->mustUseReturnValue; | ||
| } | ||
|
|
||
| public function isStaticClosure(): TrinaryLogic | ||
| { | ||
| return $this->isStatic; | ||
| } | ||
|
|
||
| public function isCloneable(): TrinaryLogic | ||
| { | ||
| return TrinaryLogic::createYes(); | ||
|
|
@@ -709,6 +785,7 @@ public function traverse(callable $cb): Type | |
| $this->acceptsNamedArguments, | ||
| $this->mustUseReturnValue, | ||
| $this->assertions, | ||
| $this->isStatic, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -761,6 +838,7 @@ public function traverseSimultaneously(Type $right, callable $cb): Type | |
| $this->acceptsNamedArguments, | ||
| $this->mustUseReturnValue, | ||
| $this->assertions, | ||
| $this->isStatic, | ||
| ); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a private methode could be created to refactor the value and precise level