@@ -77,21 +77,39 @@ private function collectDataFromTrace(array $trace): Traversable
7777 if ($ traceFunction !== $ configFunction ) {
7878 continue ;
7979 }
80+
81+ yield from self ::buildReadableRepresentationOfTrace ($ configFunction , $ argumentPaths , $ trace );
82+ }
83+ }
84+
85+ /**
86+ * @internal This method is only public because mocking \Throwable::getTrace() is not possible.
87+ *
88+ * @param string $callablePattern
89+ * @param array<string, string> $argumentPaths
90+ * @param array<mixed> $trace
91+ * @return Traversable<mixed>
92+ */
93+ public static function buildReadableRepresentationOfTrace (string $ callablePattern , array $ argumentPaths , array $ trace ): Traversable
94+ {
95+ if (!isset ($ trace ['args ' ])) {
96+ yield [$ callablePattern => ['💥 ' => 'Argument tracing is disabled. To enable, set `zend.exception_ignore_args=0` ⚙️ ' ]];
97+ } else {
8098 $ values = [];
8199 foreach ($ argumentPaths as $ argumentPathName => $ argumentPathLookup ) {
82100 try {
83- $ values [$ argumentPathName ] = $ this -> representationSerialize (
101+ $ values [$ argumentPathName ] = self :: representationSerialize (
84102 ObjectAccess::getPropertyPath ($ trace ['args ' ], $ argumentPathLookup )
85103 );
86104 } catch (Throwable $ t ) {
87105 $ values [$ argumentPathName ] = '👻 ' ;
88106 }
89107 }
90- yield [$ configFunction => $ values ];
108+ yield [$ callablePattern => $ values ];
91109 }
92110 }
93111
94- private function representationSerialize ($ value )
112+ private static function representationSerialize ($ value )
95113 {
96114 static $ representationSerialize ;
97115
@@ -136,8 +154,14 @@ private function getSettings(): Traversable
136154
137155 $ reflection = new MethodReflection ($ className , $ methodName );
138156 foreach ($ reflection ->getParameters () as $ parameter ) {
139- $ search = sprintf ('/^%s./ ' , $ parameter ->getName ());
140- $ replace = sprintf ('%d. ' , $ parameter ->getPosition ());
157+ $ search = [
158+ sprintf ('/^%s \\./ ' , $ parameter ->getName ()),
159+ sprintf ('/^%s$/ ' , $ parameter ->getName ()),
160+ ];
161+ $ replace = [
162+ sprintf ('%d. ' , $ parameter ->getPosition ()),
163+ $ parameter ->getPosition (),
164+ ];
141165 $ argumentPaths = preg_replace ($ search , $ replace , $ argumentPaths );
142166 }
143167
0 commit comments