Lets say you have 3 models like this
class User extends AbstractModel {
protected string $name = 'User';
}
class Car extends AbstractModel {
protected int $weels = 4;
}
class House extends AbstractModel {
protected string $address = 'Some Street 26a';
}
then you have a fuctions that returns the 3 models like this
protected function generateModels(): array
{
$user = new User();
$car = new Car();
$house = new House();
return [$user, $car, $house]
}
then you have some tests like this
/**
* @test
*/
public fuction this_is_some_random_test(): void
{
[
$user,
$car,
$house,
] = $this->generateModels();
$user->name;
$address->weels;
$house->address;
$result1 = some_function_require_user_model($user);
//some assertions
}
So how do you need to typehint the functions generateModels()
that PHPstan understands that It can be multiple models? cause array<int, mixed>
doesnt works array<int, AbstractModel>
also not cause it will complain like property $name doesnt exist on AbstractModel
and the third is like array<int, User|Car|House>
what also doenst seem the works cause you will get the same errors and then the functions says that the Car|House
types are now allowed. So how can I type hint it propperly?
PHPStan level 9