@@ -315,31 +315,48 @@ protected function collectVars(Throwable $exception, int $statusCode): array
315315 * @return array|object
316316 */
317317 protected function maskSensitiveData ($ trace , array $ keysToMask , string $ path = '' )
318+ {
319+ foreach ($ trace as $ i => $ line ) {
320+ $ trace [$ i ]['args ' ] = $ this ->maskData ($ line ['args ' ], $ this ->config ->sensitiveDataInTrace );
321+ }
322+
323+ return $ trace ;
324+ }
325+
326+ /**
327+ * @param array|object $args
328+ *
329+ * @return array|object
330+ */
331+ private function maskData ($ args , array $ keysToMask , string $ path = '' )
318332 {
319333 foreach ($ keysToMask as $ keyToMask ) {
320334 $ explode = explode ('/ ' , $ keyToMask );
321335 $ index = end ($ explode );
322336
323337 if (strpos (strrev ($ path . '/ ' . $ index ), strrev ($ keyToMask )) === 0 ) {
324- if (is_array ($ trace ) && array_key_exists ($ index , $ trace )) {
325- $ trace [$ index ] = '****************** ' ;
326- } elseif (is_object ($ trace ) && property_exists ($ trace , $ index ) && isset ($ trace ->{$ index })) {
327- $ trace ->{$ index } = '****************** ' ;
338+ if (is_array ($ args ) && array_key_exists ($ index , $ args )) {
339+ $ args [$ index ] = '****************** ' ;
340+ } elseif (
341+ is_object ($ args ) && property_exists ($ args , $ index )
342+ && isset ($ args ->{$ index }) && is_scalar ($ args ->{$ index })
343+ ) {
344+ $ args ->{$ index } = '****************** ' ;
328345 }
329346 }
330347 }
331348
332- if (is_array ($ trace )) {
333- foreach ($ trace as $ pathKey => $ subarray ) {
334- $ trace [$ pathKey ] = $ this ->maskSensitiveData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
349+ if (is_array ($ args )) {
350+ foreach ($ args as $ pathKey => $ subarray ) {
351+ $ args [$ pathKey ] = $ this ->maskData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
335352 }
336- } elseif (is_object ($ trace )) {
337- foreach ($ trace as $ pathKey => $ subarray ) {
338- $ trace ->{$ pathKey } = $ this ->maskSensitiveData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
353+ } elseif (is_object ($ args )) {
354+ foreach ($ args as $ pathKey => $ subarray ) {
355+ $ args ->{$ pathKey } = $ this ->maskData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
339356 }
340357 }
341358
342- return $ trace ;
359+ return $ args ;
343360 }
344361
345362 /**
0 commit comments