phpstorm-attributes
phpstorm-attributes copied to clipboard
Parameter Attribute for expected class attributes
Suggestion to add an attribute to ensure an instance has a class attribute.
class ExpectsAttribute
{
public function __construct(
#[ExpectedAttribute(CustomAttribute::class)]
object $instance,
) {
$this->instance = $instance;
}
}
#[CustomAttribute]
class MyOKClass
{
}
class NotOKClass
{
}
// OK
new ExpectsAttribute(new MyOKClass());
// Expects parameter 1 to have CustomAttribute
new ExpectsAttribute(new NotOKClass());
Thoughts?