Skip to content

Commit e4db000

Browse files
Merge branch '4.4' into 5.0
* 4.4: Provide current file as file path
2 parents eaf6791 + ec2b6b5 commit e4db000

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

DeprecationErrorHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,13 @@ public static function collectDeprecations($outputFile)
9999
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
100100
}
101101

102-
$trace = debug_backtrace();
103102
$filesStack = [];
104-
foreach ($trace as $line) {
105-
if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
103+
foreach (debug_backtrace() as $frame) {
104+
if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
106105
continue;
107106
}
108107

109-
if (isset($line['file'])) {
110-
$filesStack[] = $line['file'];
111-
}
108+
$filesStack[] = $frame['file'];
112109
}
113110

114111
$deprecations[] = [error_reporting(), $msg, $file, $filesStack];

DeprecationErrorHandler/Deprecation.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,6 @@ public function isMuted()
165165
return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR);
166166
}
167167

168-
private function getOriginalFilesStack(): array
169-
{
170-
if (null === $this->originalFilesStack) {
171-
$this->originalFilesStack = [];
172-
foreach ($this->trace as $line) {
173-
if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
174-
continue;
175-
}
176-
if (!isset($line['file'])) {
177-
continue;
178-
}
179-
$this->originalFilesStack[] = $line['file'];
180-
}
181-
}
182-
183-
return $this->originalFilesStack;
184-
}
185-
186168
/**
187169
* Tells whether both the calling package and the called package are vendor
188170
* packages.
@@ -224,6 +206,22 @@ public function getType()
224206
return self::TYPE_DIRECT;
225207
}
226208

209+
private function getOriginalFilesStack(): array
210+
{
211+
if (null === $this->originalFilesStack) {
212+
$this->originalFilesStack = [];
213+
foreach ($this->trace as $frame) {
214+
if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
215+
continue;
216+
}
217+
218+
$this->originalFilesStack[] = $frame['file'];
219+
}
220+
}
221+
222+
return $this->originalFilesStack;
223+
}
224+
227225
/**
228226
* getPathType() should always be called prior to calling this method.
229227
*

Tests/DeprecationErrorHandler/DeprecationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function providerGetTypeDetectsSelf(): array
157157
}
158158

159159
return [
160-
'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', ''],
160+
'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', __FILE__],
161161
'nonexistent_file' => [Deprecation::TYPE_UNDETERMINED, '', 'MyClass1', 'dummy_vendor_path'],
162162
'serialized_trace_with_nonexistent_triggering_file' => [
163163
Deprecation::TYPE_UNDETERMINED,

0 commit comments

Comments
 (0)