I have the following function where I only want to pull the relationships of a model:
public static function definedRelations(): array
{
$model = new static;
$relationships = [];
$class = new \ReflectionClass($model);
foreach($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method)
{
if ($method->class != get_class($model) ||
!empty($method->getParameters()) ||
$method->getName() == __FUNCTION__) {
continue;
}
try {
$return = $method->invoke($model);
if ($return instanceof Relation) {
$relationships[$method->getName()] = [
'name' => $method->getName(),
'title' => ucwords(implode(' ', preg_split('~^[^A-Z]+\K|[A-Z][^A-Z]+\K~', $method->name, 0, PREG_SPLIT_NO_EMPTY))),
'type' => (new \ReflectionClass($return))->getShortName(),
'model' => (new \ReflectionClass($return->getRelated()))->getName()
];
}
} catch(\Exception $ex) {}
}
return $relationships;
}
My problem is that when the ReflectionClass is called, it is executing the functions of that model. I am not as familiar with ReflectionClass', and I am not sure how I would "ignore" the following function on the model when executing the ReflectionClass?:
public function recalculateInvoicing(){
$invoice = $this->invoices()->firstOrNew(['charge_type_id' => 13]);
$invoice->amount = $this->citations->where('is_active', 1)->sum('amount');
$this->invoices()->save($invoice);
return $this;
}
I would appreciate any suggestions whatsoever. Thank you!