Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Optimize calls to debug_backtrace #11

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Eloquent/EmbedsRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if ($relation === null) {
[, $caller] = debug_backtrace(false);

$relation = $caller['function'];
$relation = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
}

if ($localKey === null) {
Expand Down Expand Up @@ -58,9 +56,7 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if ($relation === null) {
[, $caller] = debug_backtrace(false);

$relation = $caller['function'];
$relation = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
}

if ($localKey === null) {
Expand Down
8 changes: 2 additions & 6 deletions src/Eloquent/HybridRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if ($relation === null) {
[$current, $caller] = debug_backtrace(false, 2);

$relation = $caller['function'];
$relation = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
}

// Check if it is a relation with an original model.
Expand Down Expand Up @@ -178,9 +176,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if ($name === null) {
[$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);

$name = $caller['function'];
$name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
}

[$type, $id] = $this->getMorphs(Str::snake($name), $type, $id);
Expand Down
Loading