1010
1111final 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}
0 commit comments