-
-
Notifications
You must be signed in to change notification settings - Fork 43
Promoted properties support #90
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: main
Are you sure you want to change the base?
Conversation
Dear contributor, because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it. |
class PromotedPropertyTypeReflector extends TypeReflector | ||
{ | ||
public static function create(ReflectionProperty $reflection): self | ||
{ | ||
return new self($reflection); | ||
} | ||
|
||
public function __construct(ReflectionProperty $reflection) | ||
{ | ||
parent::__construct($reflection); | ||
} | ||
|
||
protected function getDocblock(): string | ||
{ | ||
return $this->reflection->getDeclaringClass()->getMethod('__construct')->getDocComment(); | ||
} | ||
|
||
protected function docblockRegex(): string | ||
{ | ||
$parameterName = $this->reflection->getName(); | ||
return '/@param\s+([^\s<]+(?:<[^>]*>)?)\s+\$' . preg_quote($parameterName, '/') . '\b/m'; | ||
|
||
} | ||
|
||
protected function getReflectionType(): ?ReflectionType | ||
{ | ||
return $this->reflection->getType(); | ||
} | ||
|
||
protected function getAttributes(): array | ||
{ | ||
return $this->reflection->getAttributes(); | ||
} | ||
} |
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.
Could we just use the PropertyTypeReflector
here? Since a promoted property is technically a property. We could in the constructor check if the reflection property is a promoted property and then change getDocblock
and docblockRegex
. In v3 this problem should already be fixed since we're using PHPstan annotations over there.
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.
See comment
Add support for promoted properties. The regex may need some tweaking.