@@ -127,16 +127,20 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
127
127
break ;
128
128
129
129
case Stub::TYPE_ARRAY :
130
- $ dumper ->enterHash ($ cursor , $ item ->class , $ item ->value , (bool ) $ children );
131
- $ cut = $ this ->dumpChildren ($ dumper , $ cursor , $ refs , $ children , $ cut , $ item ->class );
132
- $ dumper ->leaveHash ($ cursor , $ item ->class , $ item ->value , (bool ) $ children , $ cut );
133
- break ;
134
-
130
+ $ item = clone $ item ;
131
+ $ item ->type = $ item ->class ;
132
+ $ item ->class = $ item ->value ;
133
+ // No break;
135
134
case Stub::TYPE_OBJECT :
136
135
case Stub::TYPE_RESOURCE :
137
- $ dumper ->enterHash ($ cursor , $ item ->type , $ item ->class , (bool ) $ children );
138
- $ cut = $ this ->dumpChildren ($ dumper , $ cursor , $ refs , $ children , $ cut , $ item ->type );
139
- $ dumper ->leaveHash ($ cursor , $ item ->type , $ item ->class , (bool ) $ children , $ cut );
136
+ $ withChildren = $ children && $ cursor ->depth !== $ this ->maxDepth && $ this ->maxItemsPerDepth ;
137
+ $ dumper ->enterHash ($ cursor , $ item ->type , $ item ->class , $ withChildren );
138
+ if ($ withChildren ) {
139
+ $ cut = $ this ->dumpChildren ($ dumper , $ cursor , $ refs , $ children , $ cut , $ item ->type );
140
+ } elseif ($ children && 0 <= $ cut ) {
141
+ $ cut += count ($ children );
142
+ }
143
+ $ dumper ->leaveHash ($ cursor , $ item ->type , $ item ->class , $ withChildren , $ cut );
140
144
break ;
141
145
142
146
default :
@@ -166,26 +170,20 @@ private function dumpItem($dumper, $cursor, &$refs, $item)
166
170
*/
167
171
private function dumpChildren ($ dumper , $ parentCursor , &$ refs , $ children , $ hashCut , $ hashType )
168
172
{
169
- if ($ children ) {
170
- if ($ parentCursor ->depth !== $ this ->maxDepth && $ this ->maxItemsPerDepth ) {
171
- $ cursor = clone $ parentCursor ;
172
- ++$ cursor ->depth ;
173
- $ cursor ->hashType = $ hashType ;
174
- $ cursor ->hashIndex = 0 ;
175
- $ cursor ->hashLength = count ($ children );
176
- $ cursor ->hashCut = $ hashCut ;
177
- foreach ($ children as $ key => $ child ) {
178
- $ cursor ->hashKeyIsBinary = isset ($ key [0 ]) && !preg_match ('//u ' , $ key );
179
- $ cursor ->hashKey = $ key ;
180
- $ this ->dumpItem ($ dumper , $ cursor , $ refs , $ child );
181
- if (++$ cursor ->hashIndex === $ this ->maxItemsPerDepth || $ cursor ->stop ) {
182
- $ parentCursor ->stop = true ;
183
-
184
- return $ hashCut >= 0 ? $ hashCut + $ cursor ->hashLength - $ cursor ->hashIndex : $ hashCut ;
185
- }
186
- }
187
- } elseif ($ hashCut >= 0 ) {
188
- $ hashCut += count ($ children );
173
+ $ cursor = clone $ parentCursor ;
174
+ ++$ cursor ->depth ;
175
+ $ cursor ->hashType = $ hashType ;
176
+ $ cursor ->hashIndex = 0 ;
177
+ $ cursor ->hashLength = count ($ children );
178
+ $ cursor ->hashCut = $ hashCut ;
179
+ foreach ($ children as $ key => $ child ) {
180
+ $ cursor ->hashKeyIsBinary = isset ($ key [0 ]) && !preg_match ('//u ' , $ key );
181
+ $ cursor ->hashKey = $ key ;
182
+ $ this ->dumpItem ($ dumper , $ cursor , $ refs , $ child );
183
+ if (++$ cursor ->hashIndex === $ this ->maxItemsPerDepth || $ cursor ->stop ) {
184
+ $ parentCursor ->stop = true ;
185
+
186
+ return $ hashCut >= 0 ? $ hashCut + $ cursor ->hashLength - $ cursor ->hashIndex : $ hashCut ;
189
187
}
190
188
}
191
189
0 commit comments