Closed leiha closed 2 years ago
Hi. Do you want the completion to be inferred from the $ressources
field assigned value?
Afaik, PSALM type annotations don't provide type inference from value, not in the plugin at least.
What you could do, though, is to express the argument accepted string values through
@param $name = array_keys($this->ressources)[$any]
class SubFactory extends Factory {
protected array $ressources = [
'index' => true ,
];
/**
* @param $name = array_keys($this->ressources)[$any]
*/
public function allow( string $name ) : self {
return parent::allow( $name );
}
}
$subFactory = new SubFactory();
$subFactory->allow('');
You may find this document useful: https://github.com/klesun/deep-assoc-completion/issues/63
@klesun :pray: I had not understood how to work for my case despite the doc :( all examples had seemed for me "static" not really dynamic but maybe i'm blind ^^ it's works as you show me , perfect :)
@klesun i hope i'm not going to abuse :crossed_fingers: But can you also explain to me to have the right return type of the method ? ( With the doc i not understood again )
class SubFactory extends Factory {
protected array $ressources = [
'index' => [ 'key1' => '' , 'key2' => '' ] ,
'update' => Action\Update::class,
];
/**
* @param $name = array_keys($this->ressources)[$any]
* @return ??
*/
public function allow( string $name ) : self {
return parent::allow( $name );
}
}
$subFactory = new SubFactory();
$subFactory->allow('');
Does it not work as is already?
The : self
seems to be sufficient for the plugin to understand that return value is the class
sorry my bad i modified example for reflect the idea
class SubFactory extends Factory {
protected array $ressources = [
'index' => [ 'key1' => '' , 'key2' => '' ] ,
'update' => Action\Update::class,
];
/**
* @param $name = array_keys($this->ressources)[$any]
* @return ??
*/
public function get( string $name ) { // now the parent return item in array
return parent::get( $name );
}
}
$subFactory = new SubFactory();
$subFactory->allow('');
np
If you'll happen to want to use custom expressions in the return type, the syntax is following:
@return = array_values($this->ressources)[$any]
okay i'm idiot :pray: you're plugin is really usefull :+1: have nice day you come save mine ;)
Hi first ty for the work :pray:
I try to have a completion in factory extended i tried many things but apparently nothing work :(
There is a way to accomplish completion for param $name in allow method ?