[ 'code' => ' */ function asArray($obj) { /** @var properties-of */ $properties = []; return $properties; } class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $a = $objAsArray["a"]; $aPlus2 = $a + 2; $b = $objAsArray["b"]; if ($b === true) { echo "True!"; } $c = $objAsArray["c"]; $cConcat = $c . "foo"; ', ], 'propertiesOfTemplateParamWithTemplate' => [ 'code' => ' */ function asArray($obj) { /** @var properties-of */ $properties = []; return $properties; } /** @template T */ class A { /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; /** @param T $a */ public function __construct(public $a) {} } $obj = new A(42); $objAsArray = asArray($obj); ', 'assertions' => [ '$objAsArray===' => 'array{a: 42, b: bool, c: string, ...}', ], ], 'privatePropertiesPicksPrivate' => [ 'code' => ' */ function asArray($obj) { /** @var private-properties-of */ $properties = []; return $properties; } class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $b = $objAsArray["b"]; ', ], 'protectedPropertiesPicksProtected' => [ 'code' => ' */ function asArray($obj) { /** @var protected-properties-of */ $properties = []; return $properties; } class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $b = $objAsArray["c"]; ', ], 'publicPropertiesPicksPublic' => [ 'code' => ' */ function asArray($obj) { /** @var public-properties-of */ $properties = []; return $properties; } class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $a = $objAsArray["a"]; ', ], 'propertiesOfNestedTemplates' => [ 'code' => ' * @param TArray $array * @return properties-of */ function asArray($array) { /** @var properties-of */ $properties = []; return $properties; } class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray([$obj]); $b = $objAsArray["c"]; ', ], ]; } public function providerInvalidCodeParse(): iterable { return [ 'propertiesOfAllowsOnlyDefinedProperties' => [ 'code' => ' */ function asArray($obj) { /** @var properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $d = $objAsArray["d"]; ', 'error_message' => 'InvalidArrayOffset', ], 'privatePropertiesPicksNoPublic' => [ 'code' => ' */ function asArray($obj) { /** @var private-properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $b = $objAsArray["a"]; ', 'error_message' => 'InvalidArrayOffset', ], 'privatePropertiesPicksNoProtected' => [ 'code' => ' */ function asArray($obj) { /** @var private-properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $b = $objAsArray["c"]; ', 'error_message' => 'InvalidArrayOffset', ], 'protectedPropertiesPicksNoPublic' => [ 'code' => ' */ function asArray($obj) { /** @var protected-properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $b = $objAsArray["a"]; ', 'error_message' => 'InvalidArrayOffset', ], 'protectedPropertiesPicksNoPrivate' => [ 'code' => ' */ function asArray($obj) { /** @var protected-properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $b = $objAsArray["b"]; ', 'error_message' => 'InvalidArrayOffset', ], 'publicPropertiesPicksNoPrivate' => [ 'code' => ' */ function asArray($obj) { /** @var public-properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $a = $objAsArray["b"]; ', 'error_message' => 'InvalidArrayOffset', ], 'publicPropertiesPicksNoProtected' => [ 'code' => ' */ function asArray($obj) { /** @var public-properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray($obj); $a = $objAsArray["c"]; ', 'error_message' => 'InvalidArrayOffset', ], 'propertiesOfNestedTemplatesPickPublic' => [ 'code' => ' * @param TArray $array * @return properties-of */ function asArray($array) { /** @var properties-of */ $properties = []; return $properties; } final class A { /** @var int */ public $a = 42; /** @var bool */ private $b = true; /** @var string */ protected $c = "c"; } $obj = new A(); $objAsArray = asArray([$obj]); $b = $objAsArray["d"]; ', 'error_message' => 'InvalidArrayOffset', ], ]; } }