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 OverflowOkay, 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;
}
PHPStorm supports Psalm out of the box.
You can also use this DocBlock and don't need to redefine the shape of it later:
/**
* @return array{order_item_id: string, order_id: string, product_variation_id: string}
*/
public function toArray(): array {
return [
'order_item_id' => $this->order_item_id,
'order_id' => $this->order_id,
'product_variation_id' => $this->product_variation_id,
];
}
I love php array shapes!
PhpStorm 2020.3 will come with several PHP 8 attributes: #[ArrayShape], #[ExpectedValues], #[NoReturn], #[Pure], #[Deprecated], #[Immutable]
Using PhpStorm Php 8 attributes
Add support for JetBrains\PhpStorm\ArrayShape
I was messing around with PHP 8 and noticed that PhpStorm has some builtin attributes such as Immutable and ArrayShape. Kind of nice if only for documentation. There is a composer package to allow other static tools to possibly use them.
Given that you do end up with things like 'use JetBrains\PhpStorm\Pure;' in your source code, I was just wondering if other developers were planning to use these attributes? As opposed to perhaps waiting for some sort of 'standard' attributes to become available.