Code Duplication    Length = 57-58 lines in 2 locations

src/POData/UriProcessor/UriProcessor.php 2 locations

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