@@ -131,19 +131,18 @@ public function getElement($tag, $obj = null)
131
131
{
132
132
$ obj = $ obj ?: $ this ->getObj ();
133
133
134
- if (property_exists ($ obj , $ tag ))
134
+ if (property_exists ($ obj , $ tag )) {
135
135
return (new static ())->loadObj ($ obj ->{$ tag });
136
+ }
136
137
137
138
if ($ obj instanceof \SimpleXMLElement) {
138
139
foreach ($ obj ->children () as $ key => $ element ) {
139
-
140
- if ($ key === $ tag )
140
+ if ($ key === $ tag ) {
141
141
return (new static ())->loadObj ($ element );
142
+ }
142
143
143
- if ($ element instanceof \SimpleXMLElement) {
144
- if ($ found = $ this ->getElement ($ tag , $ element )) {
144
+ if ($ element ->count () && $ found = $ this ->getElement ($ tag , $ element )) {
145
145
return $ found ;
146
- }
147
146
}
148
147
}
149
148
}
@@ -167,7 +166,7 @@ public function getElements($tag, $obj = null)
167
166
if ($ var === $ tag ) {
168
167
$ list [] = (new static ())->loadObj ($ element );
169
168
} else {
170
- if ($ found = $ this ->getElements ($ tag , $ element )) {
169
+ if ($ element -> count () && $ found = $ this ->getElements ($ tag , $ element )) {
171
170
$ list = array_merge ($ list , $ found );
172
171
}
173
172
}
@@ -189,14 +188,14 @@ public function findValue($tag, $obj = null)
189
188
190
189
if ($ obj instanceof \SimpleXMLElement) {
191
190
foreach ($ obj ->children () as $ var => $ element ) {
192
- if ($ tag === $ var )
191
+ if ($ tag === $ var ) {
193
192
return $ this ->fetchValue ($ element );
193
+ }
194
194
195
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
196
- $ found = $ this ->findValue ($ tag , $ element );
197
-
198
- if (is_string ($ found ))
195
+ if ($ element ->count () && $ found = $ this ->findValue ($ tag , $ element )) {
196
+ if (is_string ($ found )) {
199
197
return $ found ;
198
+ }
200
199
}
201
200
}
202
201
}
@@ -224,16 +223,18 @@ public function findAttribute($name, $tag = null, $obj = null)
224
223
if ($ obj instanceof \SimpleXMLElement) {
225
224
foreach ($ obj ->children () as $ var => $ element ) {
226
225
if ($ tag ) {
227
- if ($ tag === $ var )
226
+ if ($ tag === $ var ) {
228
227
return $ this ->fetchAttr ($ name , $ element );
228
+ }
229
229
} else {
230
- if ($ att = $ this ->fetchAttr ($ name , $ element ))
230
+ if ($ att = $ this ->fetchAttr ($ name , $ element )) {
231
231
return $ att ;
232
+ }
232
233
}
233
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
234
- $ found = $ this ->findAttribute ($ name , $ tag , $ element );
235
- if (is_string ($ found ))
234
+ if ($ element ->count () && $ found = $ this ->findAttribute ($ name , $ tag , $ element )) {
235
+ if (is_string ($ found )) {
236
236
return $ found ;
237
+ }
237
238
}
238
239
}
239
240
}
@@ -259,24 +260,26 @@ public function findAttributes($names, $tag = null, $obj = null)
259
260
if ($ tag ) {
260
261
if ($ tag === $ var ) {
261
262
foreach ($ names as $ name ) {
262
- if ($ val = $ this ->fetchAttr ($ name , $ element ))
263
+ if ($ val = $ this ->fetchAttr ($ name , $ element )) {
263
264
$ return ->{$ name } = $ val ;
265
+ }
264
266
}
265
267
}
266
268
} else {
267
269
foreach ($ names as $ name ) {
268
- if ($ val = $ this ->fetchAttr ($ name , $ element ))
270
+ if ($ val = $ this ->fetchAttr ($ name , $ element )) {
269
271
$ return ->{$ name } = $ val ;
272
+ }
270
273
}
271
274
}
272
- if (!empty (get_object_vars ($ return )))
275
+ if (!empty (get_object_vars ($ return ))) {
273
276
return $ return ;
277
+ }
274
278
275
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
276
- $ found = $ this ->findAttributes ($ names , $ tag , $ element );
277
-
278
- if ($ found instanceof \stdClass)
279
+ if ($ element ->count () && $ found = $ this ->findAttributes ($ names , $ tag , $ element )) {
280
+ if ($ found instanceof \stdClass) {
279
281
return $ found ;
282
+ }
280
283
}
281
284
}
282
285
}
@@ -297,13 +300,14 @@ public function findAttributeWhere($name, $where, $obj = null)
297
300
298
301
if ($ obj instanceof \SimpleXMLElement) {
299
302
foreach ($ obj ->children () as $ var => $ element ) {
300
- if ($ this ->checkCondition ($ where , $ element ))
303
+ if ($ this ->checkCondition ($ where , $ element )) {
301
304
return $ this ->fetchAttr ($ name , $ element );
305
+ }
302
306
303
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
304
- $ found = $ this ->findAttributeWhere ($ name , $ where , $ element );
305
- if (is_string ($ found ))
307
+ if ($ element ->count () && $ found = $ this ->findAttributeWhere ($ name , $ where , $ element )) {
308
+ if (is_string ($ found )) {
306
309
return $ found ;
310
+ }
307
311
}
308
312
}
309
313
}
@@ -329,16 +333,19 @@ public function findAttributesWhere($names, $where, $obj = null)
329
333
if ($ this ->checkCondition ($ where , $ element )) {
330
334
foreach ($ names as $ name ) {
331
335
$ val = $ this ->fetchAttr ($ name , $ element );
332
- if ($ val ) $ return ->$ name = $ val ;
336
+ if ($ val ) {
337
+ $ return ->$ name = $ val ;
338
+ }
333
339
}
334
340
}
335
- if (!empty (get_object_vars ($ return )))
341
+ if (!empty (get_object_vars ($ return ))) {
336
342
return $ return ;
343
+ }
337
344
338
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
339
- $ found = $ this ->findAttributesWhere ($ names , $ where , $ element );
340
- if ($ found instanceof \stdClass)
345
+ if ($ element ->count () && $ found = $ this ->findAttributesWhere ($ names , $ where , $ element )) {
346
+ if ($ found instanceof \stdClass) {
341
347
return $ found ;
348
+ }
342
349
}
343
350
}
344
351
}
@@ -359,17 +366,19 @@ public function findAllAttributesOf($tag, $obj = null)
359
366
360
367
if ($ obj instanceof \SimpleXMLElement) {
361
368
foreach ($ obj ->children () as $ var => $ element ) {
362
- if ($ var === $ tag )
369
+ if ($ var === $ tag ) {
363
370
$ return [] = (object )current ($ element ->attributes ());
371
+ }
364
372
365
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
366
- $ found = $ this ->findAllAttributesOf ($ tag , $ element );
367
- if (is_array ($ found ))
373
+ if ($ element ->count () && $ found = $ this ->findAllAttributesOf ($ tag , $ element )) {
374
+ if (is_array ($ found )) {
368
375
return $ found ;
376
+ }
369
377
}
370
378
}
371
- if (!empty ($ return ))
379
+ if (!empty ($ return )) {
372
380
return $ return ;
381
+ }
373
382
}
374
383
return null ;
375
384
}
@@ -390,18 +399,20 @@ public function findAllAttributesOfWhere($tag, $where, $obj = null)
390
399
if ($ obj instanceof \SimpleXMLElement) {
391
400
foreach ($ obj ->children () as $ var => $ element ) {
392
401
if ($ var === $ tag ) {
393
- if ($ this ->checkCondition ($ where , $ element ))
402
+ if ($ this ->checkCondition ($ where , $ element )) {
394
403
$ return [] = (object )current ($ element ->attributes ());
404
+ }
395
405
}
396
- if ($ element instanceof \SimpleXMLElement && $ element ->count () > 0 ) {
397
- $ found = $ this ->findAllAttributesOfWhere ($ tag , $ where , $ element );
398
- if (is_array ($ found ))
406
+ if ($ element ->count () && $ found = $ this ->findAllAttributesOfWhere ($ tag , $ where , $ element )) {
407
+ if (is_array ($ found )) {
399
408
return $ found ;
409
+ }
400
410
}
401
411
}
402
412
}
403
- if (!empty ($ return ))
413
+ if (!empty ($ return )) {
404
414
return $ return ;
415
+ }
405
416
406
417
return null ;
407
418
}
0 commit comments