Okay, after posting an edit with the deep-assoc-completion link I figured out how to do this. This does what I wanted.

   foreach ($data->display_items as $line_item) {
      /** @var $metadata = CheckoutSessionLineItemMetadata::ARRAY_SHAPE */
      $metadata = $line_item->metadata;
    }
Answer from Matthew Weiner on Stack Overflow
🌐
GitHub
github.com › zircote › swagger-php › issues › 1099
Attribute class "JetBrains\PhpStorm\ArrayShape" not found · Issue #1099 · zircote/swagger-php
February 3, 2022 - After updating to the new version when I try to generate the documentation I'm getting this: [2022-02-03 20:24:22] local.ERROR: Attribute class "JetBrains\PhpStorm\ArrayShape" not found {"exception":"[object] (Error(code: 0): Attribute c...
Author   Messhias
🌐
Packagist
packagist.org › packages › jetbrains › phpstorm-attributes
jetbrains/phpstorm-attributes - Packagist.org
They are bundled with PhpStorm so you don’t need to install them separately. If you are using other static analysis tools and don’t want to get Class not found issues, then you might want to add the attributes package to your composer.json as a dev dependency: composer require --dev jetbrains/phpstorm-attributes
Discussions

php - PhpStorm hint ArrayShape? - Stack Overflow
I'm defining a class as follow, using the suggestion from https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-eap-4/#arrayshape to define the array shape as a constant so that it can be used More on stackoverflow.com
🌐 stackoverflow.com
Using PhpStorm Php 8 attributes
Psalm apparently added support for these . There was already equivalent functionality available via Psalm's own annotations so it sounds like it was just a case of mapping them to their PhpStorm equivalents. Psalm has also added similar attributes via a package, and as someone who uses Psalm and not PhpStorm that's obviously a more attractive option for me. Also, it has the advantage it can run in a CI environment. I'm also inclined to agree with the creator of Psalm that for ArrayShape the docblock version supported by Psalm is more succinct. More on reddit.com
🌐 r/PHP
20
18
February 27, 2021
Add support for JetBrains\PhpStorm\ArrayShape
Feature request https://phpstan.org/r/6f58bcf1-4f18-402e-840e-11b0f393c448 Currently, PHPStan reports Function execute() return type has no value type specified in iterable type array. when using #... More on github.com
🌐 github.com
5
April 1, 2021
[ArrayShape] Not working on properties
With the above example the autocomplete is not working... Did I do something wrong More on github.com
🌐 github.com
4
September 8, 2021
🌐
GitHub
github.com › JetBrains › phpstorm-attributes
GitHub - JetBrains/phpstorm-attributes: PhpStorm specific attributes · GitHub
They are bundled with PhpStorm so you don’t need to install them separately. If you are using other static analysis tools and don’t want to get Class not found issues, then you might want to add the attributes package to your composer.json as a dev dependency: composer require --dev jetbrains/phpstorm-attributes
Starred by 414 users
Forked by 11 users
Languages   PHP
🌐
JetBrains
blog.jetbrains.com › phpstorm › 2022 › 02 › phpstorm-2022-1-eap-3
PhpStorm 2022.1 EAP #3: Enhanced Array Shapes | The PhpStorm Blog
August 9, 2022 - To get multiline support, you had the option of using the #[ArrayShape] attribute. However, this still had no support for nested structures. In PhpStorm 2022.1, we are adding full support for multiline and nested array shapes in both PHPDoc and attributes! While PHP has a great object system, there could be times when defining a real class feels excessive and it’s more convenient to work with simple data structures or object-like arrays.
🌐
JetBrains
blog.jetbrains.com › phpstorm › 2020 › 10 › phpstorm-2020-3-eap-4
PhpStorm 2020.3 EAP #4: Custom PHP 8 Attributes | The PhpStorm Blog
June 15, 2021 - But the other part – specifying the possible keys and what value type they correspond to – was still missing. This functionality could be useful when working with simple data structures or object-like arrays when defining a real class may feel excessive. Starting from PhpStorm 2020.3, it will be possible to define the structure of such arrays with an #[ArrayShape].
🌐
GitHub
github.com › phpstan › phpstan › issues › 4790
Add support for JetBrains\PhpStorm\ArrayShape · Issue #4790 · phpstan/phpstan
April 1, 2021 - Currently, PHPStan reports Function execute() return type has no value type specified in iterable type array. when using #[ArrayShape] attribute.
Author   simPod
Find elsewhere
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › commit › master
fix: ArrayShape Attribute used wrong apostrophe and namespace fix (#12) · JetBrains/phpstorm-attributes@411f40e
June 1, 2022 - JetBrains / phpstorm-attributes Public · Notifications · Fork 10 · Star 311 · Permalink · This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files · fix: ArrayShape Attribute used wrong apostrophe and namespace fix (#12) This commit fixes the ArrayShape Attribute example since it used syntax that is incorrect (‘) and it updated the namespace `App\PHP 8\Foo::class` to `App\PHP8\Foo::class`, like the example and namespaces can not have any spaces anyways.
Author   JetBrains
🌐
JetBrains
blog.jetbrains.com › phpstorm › tag › arrayshape
ArrayShape : The PhpStorm Blog | The JetBrains Blog
This major release introduces preliminary support for generics in PHP, enums for PHP 8.1, one-line array shapes, improved automatic formatting of PHP code, new inspections and refactorings, and much more. Download PhpStorm 2021.2 Here are the main highlights of …
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › issues › 13
[ArrayShape] Not working on properties · Issue #13 · JetBrains/phpstorm-attributes
September 8, 2021 - JetBrains / phpstorm-attributes Public · Notifications · You must be signed in to change notification settings · Fork 11 · Star 411 · New issueCopy link · New issueCopy link · Closed · Closed · [ArrayShape] Not working on properties#13 · Copy link · Neirda24 · opened · on Sep 8, 2021 · Issue body actions · <?php declare(strict_types=1); namespace App; use DateTimeInterface; use IteratorAggregate; use JetBrains\PhpStorm\ArrayShape; final class MyList implements IteratorAggregate { #[ ArrayShape([ 'name' => 'string', 'from' => DateTimeInterface::class, 'to' => '?' .
Author   Neirda24
🌐
Reddit
reddit.com › r/php › phpstorm 2020.3 will come with several php 8 attributes: #[arrayshape], #[expectedvalues], #[noreturn], #[pure], #[deprecated], #[immutable]
r/PHP on Reddit: PhpStorm 2020.3 will come with several PHP 8 attributes: #[ArrayShape], #[ExpectedValues], #[NoReturn], #[Pure], #[Deprecated], #[Immutable]
October 26, 2020 - For me as a paying user of PHPStorm I don't want extra namespaced classes while the IDE still does not understand my existing annotations which I have been using for years and which have proven themselves. ... The IntelliJ IDE supports an entire programming language created by JetBrains. ... Attributes don’t need to exists as classes, only when you want to instantiate them via reflection.
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › issues › 18
[ArrayShape] doesn't work for structure inside the array · Issue #18 · JetBrains/phpstorm-attributes
January 30, 2022 - #[ArrayShape(['soldCount' => 'int', 'bookId' => 'int'])] public function foo(): array { $arr = []; $arr[] = [ 'soldCount' => 123, 'bookId' => 453478, ]; $arr[] = [ 'soldCount' => 22, 'bookId' => 7863, ]; return $arr; } I'm not able to make phpstorm to suggest 'soldCount' and 'bookId' inside foreach.
Author   hantc
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › blob › master › src › ArrayShape.php
phpstorm-attributes/src/ArrayShape.php at master · JetBrains/phpstorm-attributes
namespace JetBrains\PhpStorm; · use Attribute; · /** * The attribute specifies possible array keys and their types. * * If applied, an IDE will suggest the specified array keys, infer the specified types, and highlight non-specified keys in array access expressions. * * Array shapes should be specified with the required $shape parameter whose values should be array literals.<br /> * * Example: <br /> * <b>#[ArrayShape(["f" => "int", "string", "x" => "float"])]</b> * This usage applied on an element effectively means that the array has 3 dimensions, the keys are "f", 1, and "x", and the corresponding types are "int", "string", and "float".
Author   JetBrains
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › issues › 27
[ArrayShape] for maps/associative arrays as dynamic array indexes · Issue #27 · JetBrains/phpstorm-attributes
February 28, 2024 - Right now if I have following attribute class Shema { #[ArrayShape(['string' => Property::class])] public array $properties; } $schema->properties['prop1'] = new Property(); $shcema->properties['prop2'] = new Property(); PHPStorm (PhpSto...
Author   Justinas-Jurciukonis
🌐
JetBrains
jetbrains.com › help › inspectopedia › PhpArrayShapeCanBeAddedInspection.html
'#[ArrayShape]' attribute can be added | Inspectopedia Documentation
2 weeks ago - Reports the methods and functions that are returning arrays with known non-trivial keys. Suggests specifying the shape of the returned array via the #[ArrayShape] attribute or an array shape in the PHPDoc comment.
🌐
JetBrains
jetbrains.com › help › phpstorm › php-type-checking.html
PHP type checking | PhpStorm Documentation
February 25, 2025 - PhpStorm parses the key-value structures declared for objects and object-like arrays in PHPDoc blocks or via attributes (#[ArrayShape], #[ObjectShape]). As you type, the IDE infers the value type and invokes code completion for the keys. If automatic code completion is disabled, press Ctrl+Space or choose Code | Code Completion | Basic from the main menu. For more examples, see this blogpost. To generate an annotation for the existing object shape, place the caret at the relevant code element, press Alt+Enter, and select the Add '#[ObjectShape]' attribute or Add ObjectShape to PHPDoc context action from the menu that opens.
🌐
GitHub
github.com › vimeo › psalm › issues › 5554
Add support for JetBrains\PhpStorm\ArrayShape · Issue #5554 · vimeo/psalm
April 1, 2021 - Psalm could be able to infer array shape type from #[ArrayShape] attribute. What would be the correct approach to implement it? Should it be on psalm or Jetbrains attributes lib side? https://packagist.org/packages/jetbrains/phpstorm-attributes
Author   simPod
🌐
Long-term
doctum.long-term.support › api-docs › phpstorm-stubs › JetBrains › PhpStorm › ArrayShape.html
JetBrains\PhpStorm\ArrayShape | PHP Jetbrains phpstorm-stubs
Example: #[ArrayShape(["f" => "int", "string", "x" => "float"])] This usage applied on an element effectively means that the array has 3 dimensions, the keys are "f", 1, and "x", and the corresponding types are "int", "string", and "float". ... Generated by Doctum, a API Documentation generator and fork of Sami. This documentation is built using phpstorm-stubs from JetBrains...
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › issues › 24
Is there any documentation on ArrayShape? · Issue #24 · JetBrains/phpstorm-attributes
February 26, 2023 - // My impression, of how a solution could look like #[ArrayShape([ '*' => 'string', ])]
Author   Leonetienne