Many times I have had this scenario in php where I have a data structure but it is hard to work with because PHP doc cannot handle it.
<?php
/** @var (??) $contact */
$contact = array(
"firstName" => "John",
"lastName" => "doe",
"age" => 26,
"address" => array(
"streetAddress" => "naist street",
"city" => "Nara",
"postalCode" => "630-0192"
),
"phoneNumbers": [
array(
"type" : "mobile",
"number": "333 444 5566"
), array(
"type" : "home",
"number": "333 222 1100"
)
]
}
Perhaps PHPDoc can handle it and I just don't know how. But at least JSON Schema sounds like a great choice for documenting structures like that, and JSON objects always can be mapped 1:1 to php arrays, so here is the question:
Is there a way to document a data structure, in an IDE like PhpStorm, in a way that I would get correct type help when typing something like this?:
$contact["phoneNumbers"][0]["type"]
It is ok if the solution is not with JSON Schema, PHP doc would be enough if it could go so deep in structure.
Oh, and creating a class Contact {}
and a class PhoneNumber {}
is not feasible because the structure is not as simple as the one I mentioned here, and it would be an overkill to write all those classes just for type hinting.
Thanks in advance for your help!
JSON Schema: https://json-schema.org/learn/getting-started-step-by-step.html