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

Impossible to read properties from `#[ExpectedValues]`

Open ruudk opened this issue 3 years ago • 1 comments

Our codebase is annotated with #[ExpectedValues] and for a custom analyzer I want to read some of these but that's not possible. https://github.com/JetBrains/phpstorm-attributes/blob/411f40e9d39088e16a0475d00cc91931315120fa/src/ExpectedValues.php#L40

Please change the attributes so that the variables are public readonly or add getters so that the values can be retrieved.

ruudk avatar Jan 11 '23 08:01 ruudk

There's another way how to get the values

foreach ($reflection->getParameters() as $parameter) {
	foreach ($parameter->getAttributes(ExpectedValues::class) as $attribute) {
		$arguments = $attribute->getArguments();
		
		$values = $arguments[0] ?? $arguments['values'] ?? [];
		$flags = $arguments[1] ?? $arguments['flags'] ?? [];
		// etc.
	}
}

MartkCz avatar May 24 '24 13:05 MartkCz