JetBrains / JetBrains/phpstorm-attributes

Parameter Attribute for expected class attributes

Open
#9 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
416
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Suggestion to add an attribute to ensure an instance has a class attribute.

```php
class ExpectsAttribute
{
public function __construct(
#[ExpectedAttribute(CustomAttribute::class)]
object $instance,
) {
$this->instance = $instance;
}
}
```

```php
#[CustomAttribute]
class MyOKClass
{
}
```

```php
class NotOKClass
{
}
```

```php
// OK
new ExpectsAttribute(new MyOKClass());

// Expects parameter 1 to have CustomAttribute
new ExpectsAttribute(new NotOKClass());
```

Thoughts?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.