phpstorm-attributes icon indicating copy to clipboard operation
phpstorm-attributes copied to clipboard

Parameter Attribute for expected class attributes

Open AlexLisenkov opened this issue 3 years ago • 0 comments

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?

AlexLisenkov avatar Mar 15 '21 13:03 AlexLisenkov