Skip to content

Commit cfbff5c

Browse files
GromNaNalcaeus
authored andcommitted
Optimize calls to debug_backtrace (#11)
1 parent e1a83f4 commit cfbff5c

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/Eloquent/EmbedsRelations.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ protected function embedsMany($related, $localKey = null, $foreignKey = null, $r
2323
// the calling method's name and use that as the relationship name as most
2424
// of the time this will be what we desire to use for the relationships.
2525
if ($relation === null) {
26-
[, $caller] = debug_backtrace(false);
27-
28-
$relation = $caller['function'];
26+
$relation = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
2927
}
3028

3129
if ($localKey === null) {
@@ -58,9 +56,7 @@ protected function embedsOne($related, $localKey = null, $foreignKey = null, $re
5856
// the calling method's name and use that as the relationship name as most
5957
// of the time this will be what we desire to use for the relationships.
6058
if ($relation === null) {
61-
[, $caller] = debug_backtrace(false);
62-
63-
$relation = $caller['function'];
59+
$relation = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
6460
}
6561

6662
if ($localKey === null) {

src/Eloquent/HybridRelations.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
134134
// the calling method's name and use that as the relationship name as most
135135
// of the time this will be what we desire to use for the relationships.
136136
if ($relation === null) {
137-
[$current, $caller] = debug_backtrace(false, 2);
138-
139-
$relation = $caller['function'];
137+
$relation = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
140138
}
141139

142140
// Check if it is a relation with an original model.
@@ -178,9 +176,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
178176
// since that is most likely the name of the polymorphic interface. We can
179177
// use that to get both the class and foreign key that will be utilized.
180178
if ($name === null) {
181-
[$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
182-
183-
$name = $caller['function'];
179+
$name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
184180
}
185181

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

0 commit comments

Comments
 (0)