I want to add a type of object in @property-read and also be able to access its attributes with PhpStorm suggestions.
Here's what I would like to do:
/**
* @property-read object{type: string, schema: string} $request_schema
* @property-read object{type: string, schema: string} $response_schema
*/
class ConfigApiRoutesSchema extends BaseSchema
{
...
}
The reason I'm doing this is because I want to access the attributes type and schema, like this:
$configApiRoutesSchema = new ConfigApiRoutesSchema();
$configApiRoutesSchema->request_schema->type // Here's the problem, type is not suggested
$configApiRoutesSchema->request_schema->schema // schema is also not suggested
This is exactly what I need, but unfortunately this doesn't work for some reason. One solution is to create two classes and specify them as types:
/**
* @property-read string $type
* @property-read string $schema
*/
class RequestSchema {}
/**
* @property-read string $type
* @property-read string $schema
*/
class ResponseSchema {}
/**
* @property-read RequestSchema $request_schema
* @property-read ResponseSchema $response_schema
* @
*/
class ConfigApiRoutesSchema extends BaseSchema {}
Now PhpStorm suggests both schema and type.
But it doesn't seem correct, since RequestSchema and ResponseSchema won't actually be used. So I wonder if there's any way of using annotation with objects without having to create a class to suggest its attributes.
Thank you.