Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

martingold
Copy link

Add support for promoted properties. The regex may need some tweaking.

@spatie-bot
Copy link

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.

Comment on lines +8 to +41
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();
}
}
Copy link
Member

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.

Copy link
Member

@rubenvanassche rubenvanassche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants