@@ -33,6 +33,7 @@ public function __construct(
3333 private int $ traceLevel = 0 ,
3434 array $ excludedTracePaths = [],
3535 ) {
36+ $ this ->assertTraceLevelIsValid ($ this ->traceLevel );
3637 /** @psalm-suppress DeprecatedMethod `setExcludedTracePaths` will be private and not deprecated */
3738 $ this ->setExcludedTracePaths ($ excludedTracePaths );
3839 }
@@ -61,7 +62,9 @@ public function getContext(): array
6162 */
6263 public function setTraceLevel (int $ traceLevel ): self
6364 {
65+ $ this ->assertTraceLevelIsValid ($ traceLevel );
6466 $ this ->traceLevel = $ traceLevel ;
67+
6568 return $ this ;
6669 }
6770
@@ -114,7 +117,7 @@ private function collectTrace(array $backtrace): array
114117 if (isset ($ trace ['file ' ], $ trace ['line ' ])) {
115118 $ excludedMatch = array_filter (
116119 $ this ->excludedTracePaths ,
117- static fn ($ path ) => str_contains ($ trace ['file ' ], $ path ),
120+ static fn (string $ path ): bool => str_contains ($ trace ['file ' ], $ path ),
118121 );
119122
120123 if (empty ($ excludedMatch )) {
@@ -129,4 +132,23 @@ private function collectTrace(array $backtrace): array
129132
130133 return $ traces ;
131134 }
135+
136+ /**
137+ * Validates $traceLevel property
138+ *
139+ * @param int $traceLevel The number of call stack information.
140+ *
141+ * @see self::$traceLevel
142+ */
143+ private function assertTraceLevelIsValid (int $ traceLevel ): void
144+ {
145+ if ($ traceLevel < 0 ) {
146+ throw new InvalidArgumentException (
147+ sprintf (
148+ 'Trace level must be greater than or equal to zero, %s received. ' ,
149+ $ traceLevel ,
150+ ),
151+ );
152+ }
153+ }
132154}
0 commit comments