-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
bugSomething isn't workingSomething isn't working
Description
In our project, we have an abstract model class where each implementation's relation to another abstract model class is different:
class AbstractClassA extends ActiveRecord {
public const CLASS_B_CLASS = AbstractClassB::class;
public function getClassB() {
return $this->hasMany(static::CLASS_B_CLASS, /* condition */);
}
}
class ClassA1 extends AbstractClassA {
public const CLASS_B_CLASS = ClassB1::class;
}
class ClassA2 extends AbstractClassA {
public const CLASS_B_CLASS = ClassB2::class;
}
class AbstractClassB extends ActiveRecord {
public const CLASS_A_CLASS = AbstractClassA::class;
public function getClassA() {
return $this->hasOne(static::CLASS_A_CLASS, /* condition */);
}
}
class ClassB1 extends AbstractClassB {
public const CLASS_A_CLASS = ClassA1::class;
}
class ClassB2 extends AbstractClassB {
public const CLASS_A_CLASS = ClassA2::class;
}
This throws a PHPStan error with the message
Internal error: Invalid argument provided to method hasOne
Hint: You should use ::class instead of ::className() while analysing file
preventing any other PHPStan inspections from being applied.
Maybe you could detect if a constant passed into hasMany
or hasOne
is (always) a class string, and then use that?
erickskrauch
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working