Skip to content

Commit

Permalink
Optimize calls to debug_backtrace (mongodb#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Jul 13, 2023
1 parent 4658d54 commit 78319d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
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

0 comments on commit 78319d4

Please sign in to comment.