@@ -129,45 +129,30 @@ private function describeString(string $s, int $depth = 0): StringNode|string
129129 private function describeArray (array $ arr , int $ depth = 0 , ?int $ refId = null ): ArrayNode |ReferenceNode
130130 {
131131 if ($ refId ) {
132- $ res = new ReferenceNode ('p ' . $ refId );
133- $ node = &$ this ->snapshot [$ res ->targetId ];
132+ $ ref = new ReferenceNode ('p ' . $ refId );
133+ $ node = &$ this ->snapshot [$ ref ->targetId ];
134134 if ($ node && $ node ->depth <= $ depth ) {
135- return $ res ;
135+ return $ ref ;
136136 }
137137
138138 $ node = new ArrayNode ;
139- $ node ->id = $ res ->targetId ;
139+ $ node ->id = $ ref ->targetId ;
140140 $ node ->depth = $ depth ;
141- if ($ this ->maxDepth && $ depth >= $ this ->maxDepth ) {
142- $ node ->length = count ($ arr );
143- return $ res ;
144- } elseif ($ depth && $ this ->maxItems && count ($ arr ) > $ this ->maxItems ) {
145- $ node ->length = count ($ arr );
146- $ arr = array_slice ($ arr , 0 , $ this ->maxItems , preserve_keys: true );
147- }
148-
149- $ items = &$ node ->items ;
150-
151- } elseif ($ arr && $ this ->maxDepth && $ depth >= $ this ->maxDepth ) {
152- $ res = new ArrayNode ;
153- $ res ->length = count ($ arr );
154- return $ res ;
141+ } else {
142+ $ node = new ArrayNode ;
143+ }
155144
145+ $ node ->length = count ($ arr );
146+ if ($ arr && $ this ->maxDepth && $ depth >= $ this ->maxDepth ) {
147+ return $ ref ?? $ node ;
156148 } elseif ($ depth && $ this ->maxItems && count ($ arr ) > $ this ->maxItems ) {
157- $ res = new ArrayNode ;
158- $ res ->length = count ($ arr );
159- $ res ->depth = $ depth ;
160- $ items = &$ res ->items ;
161149 $ arr = array_slice ($ arr , 0 , $ this ->maxItems , preserve_keys: true );
162- } else {
163- $ res = new ArrayNode ;
164- $ items = &$ res ->items ;
165150 }
166151
167- $ items = [];
152+ $ node -> items = [];
168153 foreach ($ arr as $ k => $ v ) {
169154 $ refId = $ this ->getReferenceId ($ arr , $ k );
170- $ items [] = new CollectionItem (
155+ $ node -> items [] = new CollectionItem (
171156 $ this ->describeVar ($ k , $ depth + 1 ),
172157 $ this ->isSensitive ((string ) $ k , $ v )
173158 ? new TextNode (self ::hideValue ($ v ))
@@ -176,7 +161,7 @@ private function describeArray(array $arr, int $depth = 0, ?int $refId = null):
176161 );
177162 }
178163
179- return $ res ;
164+ return $ ref ?? $ node ;
180165 }
181166
182167
0 commit comments