@smacy An associative array can contain anything. If you want to add meaning, then use a type that explicitly declares that meaning; not a generic data type such as an array.
How to enhance IDE hints for method parameters in Laravel using PHPDoc?
I'm working on a Laravel project, and I want to improve the code hints provided by my IDE (Integrated Development Environment) when calling methods with array parameters. Specifically, I have a class ClassA with a method methodA that accepts an associative array, and I want my IDE to provide suggestions for the keys and their data types.
interface ClassAInterface{
public function methodA($array);
}
class ClassA implements ClassAInterface{
public function methodA($array){
$data = Http::withHeaders([
'Authorization' => 'key '.config('any.secret_key'),
])->post(config('any.initiate_url'), [
'return_url' => config('any.return_url'),
'website_url' => config('any.website_url'),
'amount' => $array['amount'],
'purchase_order_id' => $array['purchaseOrderId'],
'purchase_order_name' => $array['purchaseOrderName'],
'customer_info' => $array['customerInfo'],
]);
return json_decode($data->body(), true);
}
}
class ClassB{
public function methodB(){
$data=[
'amount'=>1000,
'purchaseOrderId'=>1,
'purchaseOrderName'=>'test',
'customerInfo'=>'test'
];
$class=new ClassA();
return $class->methodA($data);
}
}
Despite this, my IDE is not providing suggestions for these keys when calling methodA in ClassB. Additionally, I'm curious about how to best implement this interface for dependency injection in Laravel.
Could anyone guide how to enhance PHPDoc comments for better IDE hints and also share insights on implementing the interface as a dependency injection in Laravel?
Thank you for your assistance!
Please or to participate in this conversation.