klesun / deep-assoc-completion

A phpstorm plugin for associative array key typing and completion
Other
267 stars 17 forks source link

Support PHP 8 Constructor Promotions #189

Open klesun opened 3 years ago

klesun commented 3 years ago

image

Consider this ctor.

When I instantiate this class, I don't get suggestions of ro-user or ro-password for $config array (first argument)

See https://php.watch/versions/8.0/constructor-property-promotion#:~:text=Constructor%20Property%20Promotion%20is%20a%20shorthand%20syntax%20to%20declare%20and,additional%20code%20within%20the%20constructor.

For time being a workaround is to go the pre-php8 way:

private $config;
private $adminConfig;

/**
 * @param array{
 *     user: string,
 *     pass: string,
 *     host: string,
 *     ro-user: string,
 *     ro-pass: string,
 *     ro-host: string,
 *     dbname: string,
 * } $config
 *
 * @param array {
 *     user: string,
 *     pass: string,
 * } $adminConfig
 */
public function __construct($config, $adminConfig)
{
    $this->config = $config;
    $this->adminConfig = $adminConfig;
}