Open dereuromark opened 6 months ago
If I understood the question correctly, the format from phpstan and other linters does cover the union type and the string literal type, so following should work in the plugin: (unless some breaking change in modern IDE versions broke that)
/**
* @param array<'className' | 'targetTable' | 'foreignKey' | 'dependent' | 'cascadeCallbacks' | 'conditions' | 'sort' | 'saveStrategy' | 'strategy' | 'finder', mixed> $options list of options to configure the association definition
*/
public function hasMany(string $associated, array $options = []): HasMany
{
$options['<completion should come up here>']
I mean from the outside, the using function of ->hasMany() See my example.
Your code snippet does not seem to work. Only AI (tabinePro in my case) seems to sometimes guess the possible types correctly, but more like 20% of the time.
That said
@param array{className: string, targetTable: string, foreignKey: string, webroot: string, dependent: bool, cascadeCallbacks: bool, conditions: array, sort: array, saveStrategy: string, finder: string} $options List of options to configure the association definition
seems to work, but that makes the docblock line super loong, would be nice if there was a way outside of the param docblock line directly.
When completion works it suppossedly works both inside and outside the ->hasMany()
function.
One more way, specific to the plugin, is to express the type through a dummy function:
function hasManyOptionsType()
{
return [
/** The class name of the target table object */
'className' => 'example value',
/** An instance of a table object to be used as the target table */
'targetTable' => 'example value',
/** The name of the field to use as foreign key, if false none will ve used */
'foreignKey' => 'example value',
// and so on
];
}
class Something()
{
/**
* @param $options = hasManyOptionsType()
*/
public function hasMany(string $associated, array $options = []): HasMany
{
$options['<completion should come up here>']
}
}
(new Something())->hasMany('ADmad/SocialAuth.SocialProfiles', [
'<completion should come up here too>'
]);
Refs https://github.com/dereuromark/cakephp-ide-helper/issues/346
Would be nice if we could use some kind of option keys list in the docblock to document all possible array keys for assoc arrays.
So when someone types
it would autocomplete the
foreignKey
option right away.Or are there other ways of accomplishing this?
The method and its docblock currently reads as
If sth like this list is not formal enough, maybe we can find a syntax for it that is.