Code Duplication    Length = 57-58 lines in 2 locations

src/POData/UriProcessor/UriProcessor.php 2 locations

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