src/ArtaxServiceBuilder/Service/GithubPaginator.php
function makeDramaticAssumptionsAboutLinks(array $links) {

        $earliestKnownLink = null;
        $earliestType = null;

        $furthestKnownLink = null;
        $furthestType = null;
        
        $nextLink = null;

        if (isset($links[self::FIRST]) == true) {
            $earliestKnownLink = $links[self::FIRST];
            $earliestType = self::FIRST;
        }
        else if (isset($links[self::PREVIOUS]) == true) {
            $earliestKnownLink = $links[self::PREVIOUS];
            $earliestType = self::PREVIOUS;
        }
        else if (isset($links[self::NEXT]) == true) {
            $earliestKnownLink = $links[self::NEXT];
            $earliestType = self::NEXT;
        }

        if (isset($links[self::LAST]) == true) {
            $furthestKnownLink = $links[self::LAST];
            $furthestType = self::LAST;
        }
        else if (isset($links[self::NEXT]) == true) {
            $furthestKnownLink = $links[self::NEXT];
            $furthestType = self::NEXT;
            $nextLink = $links[self::NEXT];
        }
        else if (isset($links[self::PREVIOUS]) == true) {
            $furthestKnownLink = $links[self::PREVIOUS];
            $furthestType = self::PREVIOUS;
        }

        
        if (isset(self::$typeOrder[$furthestType]) &&
            isset(self::$typeOrder[$earliestType])) {
            if (self::$typeOrder[$furthestType] <
                self::$typeOrder[$earliestType]
            ) {
                //TODO - links are borked.
            }
        }


        $urlStub1 = null;
        $urlStub2 = null;
        
        if  ($earliestKnownLink) {
            if (preg_match('/(.*page=)(\d+)$/', $earliestKnownLink->url, $matches)) {
                $urlStub1 = $matches[1];
                $this->earliestPage = intval($matches[2]);
            }
        }

        if  ($furthestKnownLink) {
            if (preg_match('/(.*page=)(\d+)$/', $furthestKnownLink->url, $matches)) {
                $urlStub2 = $matches[1];
                $this->furthestPage = intval($matches[2]);
            }
        }

        if  ($nextLink) {
            if (preg_match('/(.*page=)(\d+)$/', $nextLink->url, $matches)) {
                $urlStub2 = $matches[1];
                $this->nextPage = intval($matches[2]);
            }
        }


        if ($urlStub1 && $urlStub2) {
            //TODO - what do we do when they don't match?
        }

        if ($urlStub1) {
            $this->urlStub = $urlStub1;
        }
        else if ($urlStub2) {
            $this->urlStub = $urlStub2;
        }
    }
function makeDramaticAssumptionsAboutLinks(array $links) {

        $earliestKnownLink = null;
        $earliestType = null;

        $furthestKnownLink = null;
        $furthestType = null;
        
        $nextLink = null;

        if (isset($links[self::FIRST]) == true) {
            $earliestKnownLink = $links[self::FIRST];
            $earliestType = self::FIRST;
        }
        else if (isset($links[self::PREVIOUS]) == true) {
            $earliestKnownLink = $links[self::PREVIOUS];
            $earliestType = self::PREVIOUS;
        }
        else if (isset($links[self::NEXT]) == true) {
            $earliestKnownLink = $links[self::NEXT];
            $earliestType = self::NEXT;
        }

        if (isset($links[self::LAST]) == true) {
            $furthestKnownLink = $links[self::LAST];
            $furthestType = self::LAST;
        }
        else if (isset($links[self::NEXT]) == true) {
            $furthestKnownLink = $links[self::NEXT];
            $furthestType = self::NEXT;
            $nextLink = $links[self::NEXT];
        }
        else if (isset($links[self::PREVIOUS]) == true) {
            $furthestKnownLink = $links[self::PREVIOUS];
            $furthestType = self::PREVIOUS;
        }

        
        if (isset(self::$typeOrder[$furthestType]) &&
            isset(self::$typeOrder[$earliestType])) {
            if (self::$typeOrder[$furthestType] <
                self::$typeOrder[$earliestType]
            ) {
                //TODO - links are borked.
            }
        }


        $urlStub1 = null;
        $urlStub2 = null;
        
        if  ($earliestKnownLink) {
            if (preg_match('/(.*page=)(\d+)$/', $earliestKnownLink->url, $matches)) {
                $urlStub1 = $matches[1];
                $this->earliestPage = intval($matches[2]);
            }
        }

        if  ($furthestKnownLink) {
            if (preg_match('/(.*page=)(\d+)$/', $furthestKnownLink->url, $matches)) {
                $urlStub2 = $matches[1];
                $this->furthestPage = intval($matches[2]);
            }
        }

        if  ($nextLink) {
            if (preg_match('/(.*page=)(\d+)$/', $nextLink->url, $matches)) {
                $urlStub2 = $matches[1];
                $this->nextPage = intval($matches[2]);
            }
        }


        if ($urlStub1 && $urlStub2) {
            //TODO - what do we do when they don't match?
        }

        if ($urlStub1) {
            $this->urlStub = $urlStub1;
        }
        else if ($urlStub2) {
            $this->urlStub = $urlStub2;
        }
    }
function makeDramaticAssumptionsAboutLinks ( array $ links ) { $ earliestKnownLink = null ; $ earliestType = null ; $ furthestKnownLink = null ; $ furthestType = null ; $ nextLink = null ; if ( isset ( $ links [ self :: FIRST ] ) == true ) { $ earliestKnownLink = $ links [ self :: FIRST ] ; $ earliestType = self :: FIRST ; } else if ( isset ( $ links [ self :: PREVIOUS ] ) == true ) { $ earliestKnownLink = $ links [ self :: PREVIOUS ] ; $ earliestType = self :: PREVIOUS ; } else if ( isset ( $ links [ self :: NEXT ] ) == true ) { $ earliestKnownLink = $ links [ self :: NEXT ] ; $ earliestType = self :: NEXT ; } if ( isset ( $ links [ self :: LAST ] ) == true ) { $ furthestKnownLink = $ links [ self :: LAST ] ; $ furthestType = self :: LAST ; } else if ( isset ( $ links [ self :: NEXT ] ) == true ) { $ furthestKnownLink = $ links [ self :: NEXT ] ; $ furthestType = self :: NEXT ; $ nextLink = $ links [ self :: NEXT ] ; } else if ( isset ( $ links [ self :: PREVIOUS ] ) == true ) { $ furthestKnownLink = $ links [ self :: PREVIOUS ] ; $ furthestType = self :: PREVIOUS ; } if ( isset ( self :: $ typeOrder [ $ furthestType ] ) && isset ( self :: $ typeOrder [ $ earliestType ] ) ) { if ( self :: $ typeOrder [ $ furthestType ] < self :: $ typeOrder [ $ earliestType ] ) { //TODO - links are borked. } } $ urlStub1 = null ; $ urlStub2 = null ; if ( $ earliestKnownLink ) { if ( preg_match ( '/(.*page=)(\d+)$/' , $ earliestKnownLink -> url , $ matches ) ) { $ urlStub1 = $ matches [ 1 ] ; $ this -> earliestPage = intval ( $ matches [ 2 ] ) ; } } if ( $ furthestKnownLink ) { if ( preg_match ( '/(.*page=)(\d+)$/' , $ furthestKnownLink -> url , $ matches ) ) { $ urlStub2 = $ matches [ 1 ] ; $ this -> furthestPage = intval ( $ matches [ 2 ] ) ; } } if ( $ nextLink ) { if ( preg_match ( '/(.*page=)(\d+)$/' , $ nextLink -> url , $ matches ) ) { $ urlStub2 = $ matches [ 1 ] ; $ this -> nextPage = intval ( $ matches [ 2 ] ) ; } } if ( $ urlStub1 && $ urlStub2 ) { //TODO - what do we do when they don't match? } if ( $ urlStub1 ) { $ this -> urlStub = $ urlStub1 ; } else if ( $ urlStub2 ) { $ this -> urlStub = $ urlStub2 ; } }
This is a stupid function and I feel bad writing it, but it's not my fault.
Github return information about what links are available in text in the rel
links.....which means we need to manually extract the information about
what pages are available by hand. Which sucks, as it just completely fragile
and makes dramatic assumptions about the URI that github has return to us
@param \ArtaxServiceBuilder\Service\Link[] $links
This is a stupid function and I feel bad writing it but it s not my fault . Github return information about what links are available in text in the rel links ..... which means we need to manually extract the information about what pages are available by hand . Which sucks as it just completely fragile and makes dramatic assumptions about the URI that github has return to us