Code Duplication    Length = 57-59 lines in 2 locations

src/POData/UriProcessor/UriProcessor.php 2 locations

@@ 414-470 (lines=57) @@
411
            if (is_array($result)) {
412
                foreach ($result as $entry) {
413
                    // Check for null entry
414
                    if ($isCollection) {
415
                        $currentResourceSet = $this->_getCurrentResourceSetWrapper()->getResourceSet();
416
                        $resourceSetOfProjectedProperty = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
417
                        $projectedProperty1 = $expandedProjectionNode->getResourceProperty();
418
                        $result1 = $this->providers->getRelatedResourceSet(
419
	                        QueryType::ENTITIES(), //it's always entities for an expansion
420
                            $currentResourceSet,
421
                            $entry,
422
                            $resourceSetOfProjectedProperty,
423
                            $projectedProperty1,
424
                            null, // $filter
425
                            null, // $orderby
426
                            null, // $top
427
                            null  // $skip
428
                        )->results;
429
                        if (!empty($result1)) {
430
                            $internalOrderByInfo = $expandedProjectionNode->getInternalOrderByInfo();
431
                            if (!is_null($internalOrderByInfo)) {
432
                                $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
433
                                usort($result1, $orderByFunction);
434
                                unset($internalOrderByInfo);
435
                                $takeCount = $expandedProjectionNode->getTakeCount();
436
                                if (!is_null($takeCount)) {
437
                                    $result1 = array_slice($result1, 0, $takeCount);
438
                                }
439
                            }
440
441
                            $entry->$expandedPropertyName = $result1;
442
                            $projectedProperty = $expandedProjectionNode->getResourceProperty();
443
                            $needPop = $this->_pushSegmentForNavigationProperty(
444
                                $projectedProperty
445
                            );
446
                            $this->_executeExpansion($result1);
447
                            $this->_popSegment($needPop);
448
                        } else {
449
                            $entry->$expandedPropertyName = array();
450
                        }
451
                    } else {
452
                        $currentResourceSet1 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
453
                        $resourceSetOfProjectedProperty1 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
454
                        $projectedProperty2 = $expandedProjectionNode->getResourceProperty();
455
                        $result1 = $this->providers->getRelatedResourceReference(
456
                            $currentResourceSet1,
457
                            $entry,
458
                            $resourceSetOfProjectedProperty1,
459
                            $projectedProperty2
460
                        );
461
                        $entry->$expandedPropertyName = $result1;
462
                        if (!is_null($result1)) {
463
                            $projectedProperty3 = $expandedProjectionNode->getResourceProperty();
464
                            $needPop = $this->_pushSegmentForNavigationProperty(
465
                                $projectedProperty3
466
                            );
467
                            $this->_executeExpansion($result1);
468
                            $this->_popSegment($needPop);
469
                        }
470
                    }
471
                }
472
            } else {
473
                if ($isCollection) {
@@ 472-530 (lines=59) @@
469
                        }
470
                    }
471
                }
472
            } else {
473
                if ($isCollection) {
474
                    $currentResourceSet2 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
475
                    $resourceSetOfProjectedProperty2 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
476
                    $projectedProperty4 = $expandedProjectionNode->getResourceProperty();
477
                    $result1 = $this->providers->getRelatedResourceSet(
478
	                    QueryType::ENTITIES(), //it's always entities for an expansion
479
                        $currentResourceSet2,
480
                        $result,
481
                        $resourceSetOfProjectedProperty2,
482
                        $projectedProperty4,
483
                        null, // $filter
484
                        null, // $orderby
485
                        null, // $top
486
                        null  // $skip
487
                    )->results;
488
                    if (!empty($result1)) {
489
                        $internalOrderByInfo = $expandedProjectionNode->getInternalOrderByInfo();
490
                        if (!is_null($internalOrderByInfo)) {
491
                            $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
492
                            usort($result1, $orderByFunction);
493
                            unset($internalOrderByInfo);
494
                            $takeCount = $expandedProjectionNode->getTakeCount();
495
                            if (!is_null($takeCount)) {
496
                                $result1 = array_slice($result1, 0, $takeCount);
497
                            }
498
                        }
499
500
                        $result->$expandedPropertyName = $result1;
501
                        $projectedProperty7 = $expandedProjectionNode->getResourceProperty();
502
                        $needPop = $this->_pushSegmentForNavigationProperty(
503
                            $projectedProperty7
504
                        );
505
                        $this->_executeExpansion($result1);
506
                        $this->_popSegment($needPop);
507
                    } else {
508
                        $result->$expandedPropertyName = array();
509
                    }
510
                } else {
511
                    $currentResourceSet3 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
512
                    $resourceSetOfProjectedProperty3 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
513
                    $projectedProperty5 = $expandedProjectionNode->getResourceProperty();
514
                    $result1 = $this->providers->getRelatedResourceReference(
515
                        $currentResourceSet3,
516
                        $result,
517
                        $resourceSetOfProjectedProperty3,
518
                        $projectedProperty5
519
                    );
520
                    $result->$expandedPropertyName = $result1;
521
                    if (!is_null($result1)) {
522
                        $projectedProperty6 = $expandedProjectionNode->getResourceProperty();
523
                        $needPop = $this->_pushSegmentForNavigationProperty(
524
                            $projectedProperty6
525
                        );
526
                        $this->_executeExpansion($result1);
527
                        $this->_popSegment($needPop);
528
                    }
529
                }
530
            }
531
        }
532
    }
533