Code Duplication    Length = 57-58 lines in 2 locations

src/POData/UriProcessor/UriProcessor.php 2 locations

@@ 538-594 (lines=57) @@
535
            if (is_array($result)) {
536
                foreach ($result as $entry) {
537
                    // Check for null entry
538
                    if ($isCollection) {
539
                        $currentResourceSet = $this->_getCurrentResourceSetWrapper()->getResourceSet();
540
                        $resourceSetOfProjectedProperty = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
541
                        $projectedProperty1 = $expandedProjectionNode->getResourceProperty();
542
                        $result1 = $this->providers->getRelatedResourceSet(
543
                            QueryType::ENTITIES(), //it's always entities for an expansion
544
                            $currentResourceSet,
545
                            $entry,
546
                            $resourceSetOfProjectedProperty,
547
                            $projectedProperty1,
548
                            null, // $filter
549
                            null, // $orderby
550
                            null, // $top
551
                            null  // $skip
552
                        )->results;
553
                        if (!empty($result1)) {
554
                            $internalOrderByInfo = $expandedProjectionNode->getInternalOrderByInfo();
555
                            if (!is_null($internalOrderByInfo)) {
556
                                $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
557
                                usort($result1, $orderByFunction);
558
                                unset($internalOrderByInfo);
559
                                $takeCount = $expandedProjectionNode->getTakeCount();
560
                                if (!is_null($takeCount)) {
561
                                    $result1 = array_slice($result1, 0, $takeCount);
562
                                }
563
                            }
564
565
                            $resourceType->setPropertyValue($entry, $expandedPropertyName, $result1);
566
                            $projectedProperty = $expandedProjectionNode->getResourceProperty();
567
                            $needPop = $this->_pushSegmentForNavigationProperty(
568
                                $projectedProperty
569
                            );
570
                            $this->_executeExpansion($result1);
571
                            $this->_popSegment($needPop);
572
                        } else {
573
                            $resourceType->setPropertyValue($entry, $expandedPropertyName, array());
574
                        }
575
                    } else {
576
                        $currentResourceSet1 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
577
                        $resourceSetOfProjectedProperty1 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
578
                        $projectedProperty2 = $expandedProjectionNode->getResourceProperty();
579
                        $result1 = $this->providers->getRelatedResourceReference(
580
                            $currentResourceSet1,
581
                            $entry,
582
                            $resourceSetOfProjectedProperty1,
583
                            $projectedProperty2
584
                        );
585
                        $resourceType->setPropertyValue($entry, $expandedPropertyName, $result1);
586
                        if (!is_null($result1)) {
587
                            $projectedProperty3 = $expandedProjectionNode->getResourceProperty();
588
                            $needPop = $this->_pushSegmentForNavigationProperty(
589
                                $projectedProperty3
590
                            );
591
                            $this->_executeExpansion($result1);
592
                            $this->_popSegment($needPop);
593
                        }
594
                    }
595
                }
596
            } else {
597
                if ($isCollection) {
@@ 596-653 (lines=58) @@
593
                        }
594
                    }
595
                }
596
            } else {
597
                if ($isCollection) {
598
                    $currentResourceSet2 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
599
                    $resourceSetOfProjectedProperty2 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
600
                    $projectedProperty4 = $expandedProjectionNode->getResourceProperty();
601
                    $result1 = $this->providers->getRelatedResourceSet(
602
                        QueryType::ENTITIES(), //it's always entities for an expansion
603
                        $currentResourceSet2,
604
                        $result,
605
                        $resourceSetOfProjectedProperty2,
606
                        $projectedProperty4,
607
                        null, // $filter
608
                        null, // $orderby
609
                        null, // $top
610
                        null  // $skip
611
                    )->results;
612
                    if (!empty($result1)) {
613
                        $internalOrderByInfo = $expandedProjectionNode->getInternalOrderByInfo();
614
                        if (!is_null($internalOrderByInfo)) {
615
                            $orderByFunction = $internalOrderByInfo->getSorterFunction()->getReference();
616
                            usort($result1, $orderByFunction);
617
                            unset($internalOrderByInfo);
618
                            $takeCount = $expandedProjectionNode->getTakeCount();
619
                            if (!is_null($takeCount)) {
620
                                $result1 = array_slice($result1, 0, $takeCount);
621
                            }
622
                        }
623
                        $resourceType->setPropertyValue($result, $expandedPropertyName, $result1);
624
                        $projectedProperty7 = $expandedProjectionNode->getResourceProperty();
625
                        $needPop = $this->_pushSegmentForNavigationProperty(
626
                            $projectedProperty7
627
                        );
628
                        $this->_executeExpansion($result1);
629
                        $this->_popSegment($needPop);
630
                    } else {
631
                        $resourceType->setPropertyValue($result, $expandedPropertyName, $result1);
632
                    }
633
                } else {
634
                    $currentResourceSet3 = $this->_getCurrentResourceSetWrapper()->getResourceSet();
635
                    $resourceSetOfProjectedProperty3 = $expandedProjectionNode->getResourceSetWrapper()->getResourceSet();
636
                    $projectedProperty5 = $expandedProjectionNode->getResourceProperty();
637
                    $result1 = $this->providers->getRelatedResourceReference(
638
                        $currentResourceSet3,
639
                        $result,
640
                        $resourceSetOfProjectedProperty3,
641
                        $projectedProperty5
642
                    );
643
                    $resourceType->setPropertyValue($result, $expandedPropertyName, $result1);
644
                    if (!is_null($result1)) {
645
                        $projectedProperty6 = $expandedProjectionNode->getResourceProperty();
646
                        $needPop = $this->_pushSegmentForNavigationProperty(
647
                            $projectedProperty6
648
                        );
649
                        $this->_executeExpansion($result1);
650
                        $this->_popSegment($needPop);
651
                    }
652
                }
653
            }
654
        }
655
    }
656