Skip to content

Commit 4b72a9e

Browse files
committed
refactor: minor cleanup
1 parent 2ca8f44 commit 4b72a9e

File tree

5 files changed

+22
-37
lines changed

5 files changed

+22
-37
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@
270270
"./bin/validate-packages",
271271
"./tempest discovery:clear --no-interaction",
272272
"composer phpunit",
273-
"composer phpstan"
273+
"composer phpstan",
274+
"composer exceptions:build"
274275
]
275276
}
276277
}

packages/debug/src/Stacktrace/Frame.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ final class Frame
1616
* @param array<Argument> $arguments
1717
*/
1818
public function __construct(
19-
private(set) string $file,
2019
private(set) int $line,
2120
private(set) ?string $class,
2221
private(set) ?string $function,
@@ -41,7 +40,6 @@ public static function fromArray(array $frame, int $contextLines = 5, ?string $r
4140
}
4241

4342
return new self(
44-
file: $absoluteFile,
4543
line: $line,
4644
class: $frame['class'] ?? null,
4745
function: $frame['function'] ?? null,

packages/debug/src/Stacktrace/Stacktrace.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010

1111
final class Stacktrace
1212
{
13-
/**
14-
* @param array<int, Frame> $frames
15-
*/
13+
/** @var array<Frame> */
1614
public array $applicationFrames {
1715
get => array_values(array_filter(
1816
array: $this->frames,
1917
callback: fn (Frame $frame) => ! $frame->isVendor,
2018
));
2119
}
2220

23-
/**
24-
* @param array<int, Frame> $frames
25-
*/
21+
/** @var array<int,Frame> */
2622
public array $vendorFrames {
2723
get => array_values(array_filter(
2824
array: $this->frames,
@@ -31,13 +27,12 @@ final class Stacktrace
3127
}
3228

3329
/**
34-
* @param array<int, Frame> $frames
30+
* @param array<int,Frame> $frames
3531
*/
3632
public function __construct(
3733
private(set) string $message,
3834
private(set) string $exceptionClass,
3935
private(set) array $frames,
40-
private(set) string $file,
4136
private(set) int $line,
4237
private(set) string $absoluteFile,
4338
private(set) string $relativeFile,
@@ -46,10 +41,9 @@ public function __construct(
4641
public static function fromThrowable(Throwable $throwable, int $contextLines = 5, ?string $rootPath = null): self
4742
{
4843
$frames = [];
44+
$snippet = null;
4945
$trace = $throwable->getTrace();
5046
$firstTraceFrame = $trace[0] ?? null;
51-
$snippet = null;
52-
5347
$exceptionFile = $throwable->getFile();
5448
$exceptionLine = $throwable->getLine();
5549
$isVendor = Frame::isVendorFile($exceptionFile, $rootPath);
@@ -58,39 +52,34 @@ public static function fromThrowable(Throwable $throwable, int $contextLines = 5
5852
$snippet = Frame::extractCodeSnippet($exceptionFile, $exceptionLine, $contextLines);
5953
}
6054

61-
$absoluteExceptionFile = $exceptionFile;
62-
$relativeExceptionFile = $rootPath ? to_relative_path($rootPath, $exceptionFile) : $exceptionFile;
63-
$arguments = $firstTraceFrame ? Frame::extractArguments($firstTraceFrame) : [];
64-
6555
$frames[] = new Frame(
66-
file: $exceptionFile,
6756
line: $exceptionLine,
6857
class: $firstTraceFrame['class'] ?? null,
6958
function: $firstTraceFrame['function'] ?? null,
7059
type: $firstTraceFrame['type'] ?? null,
7160
isVendor: $isVendor,
7261
snippet: $snippet,
73-
absoluteFile: $absoluteExceptionFile,
74-
relativeFile: $relativeExceptionFile,
75-
arguments: $arguments,
62+
absoluteFile: $exceptionFile,
63+
relativeFile: $rootPath
64+
? to_relative_path($rootPath, $exceptionFile)
65+
: $exceptionFile,
66+
arguments: $firstTraceFrame
67+
? Frame::extractArguments($firstTraceFrame)
68+
: [],
7669
index: 1,
7770
);
7871

79-
foreach (array_slice($trace, 1) as $i => $frame) {
72+
foreach (array_slice($trace, offset: 1) as $i => $frame) {
8073
$frames[] = Frame::fromArray($frame, $contextLines, $rootPath, $i + 2);
8174
}
8275

83-
$absoluteFile = $throwable->getFile();
84-
$relativeFile = $rootPath ? to_relative_path($rootPath, $absoluteFile) : $absoluteFile;
85-
8676
return new self(
8777
message: $throwable->getMessage(),
8878
exceptionClass: $throwable::class,
8979
frames: $frames,
90-
file: $throwable->getFile(),
9180
line: $throwable->getLine(),
92-
absoluteFile: $absoluteFile,
93-
relativeFile: $relativeFile,
81+
absoluteFile: $exceptionFile,
82+
relativeFile: $rootPath ? to_relative_path($rootPath, $exceptionFile) : $exceptionFile,
9483
);
9584
}
9685
}

packages/debug/tests/StacktraceTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function stacktrace_frame_creates_from_array(): void
4848
'type' => '->',
4949
]);
5050

51-
$this->assertSame(__FILE__, $frame->file);
51+
$this->assertSame(__FILE__, $frame->absoluteFile);
5252
$this->assertSame(100, $frame->line);
5353
$this->assertSame(self::class, $frame->class);
5454
$this->assertSame('testMethod', $frame->function);
@@ -206,17 +206,15 @@ public function detects_vendor_files_with_root_path(): void
206206
public function stacktrace_uses_root_path_for_vendor_detection(): void
207207
{
208208
$exception = $this->createException();
209-
$rootPath = dirname(__DIR__, 3); // Get project root
209+
$rootPath = dirname(__DIR__, levels: 3); // Get project root
210210

211211
$stacktrace = Stacktrace::fromThrowable($exception, rootPath: $rootPath);
212+
$frames = $stacktrace->applicationFrames;
212213

213-
$appFrames = $stacktrace->applicationFrames;
214+
$this->assertNotEmpty($frames);
214215

215-
$this->assertNotEmpty($appFrames);
216-
217-
foreach ($appFrames as $frame) {
218-
// Check that files within the project are not marked as vendor
219-
if (str_starts_with($frame->file, $rootPath)) {
216+
foreach ($frames as $frame) {
217+
if (str_starts_with($frame->absoluteFile, $rootPath)) {
220218
$this->assertFalse($frame->isVendor);
221219
}
222220
}

packages/router/src/Exceptions/local/src/components/stacktrace/stacktrace.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export interface Argument {
1212
}
1313

1414
export interface StacktraceFrame {
15-
file: string
1615
line: number
1716
class?: string
1817
function?: string

0 commit comments

Comments
 (0)