Code Duplication    Length = 24-24 lines in 2 locations

controller/RestController.php 2 locations

@@ 621-644 (lines=24) @@
618
     * @param Request $request
619
     * @return object json-ld wrapped broader transitive concept uris and labels.
620
     */
621
    public function broaderTransitive($request)
622
    {
623
        $results = array();
624
        $broaders = $request->getVocab()->getConceptTransitiveBroaders($request->getUri(), $this->parseLimit(), false, $request->getLang());
625
        if (empty($broaders)) {
626
            return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
627
        }
628
629
        foreach ($broaders as $buri => $vals) {
630
            $result = array('uri' => $buri, 'prefLabel' => $vals['label']);
631
            if (isset($vals['direct'])) {
632
                $result['broader'] = $vals['direct'];
633
            }
634
            $results[$buri] = $result;
635
        }
636
637
        $ret = array_merge_recursive($this->context, array(
638
            '@context' => array('prefLabel' => 'skos:prefLabel', 'broader' => array('@id' => 'skos:broader', '@type' => '@id'), 'broaderTransitive' => array('@id' => 'skos:broaderTransitive', '@container' => '@index'), '@language' => $request->getLang()),
639
            'uri' => $request->getUri(),
640
            'broaderTransitive' => $results)
641
        );
642
643
        return $this->returnJson($ret);
644
    }
645
646
    /**
647
     * Used for querying narrower relations for a concept.
@@ 677-700 (lines=24) @@
674
     * @param Request $request
675
     * @return object json-ld wrapped narrower transitive concept uris and labels.
676
     */
677
    public function narrowerTransitive($request)
678
    {
679
        $results = array();
680
        $narrowers = $request->getVocab()->getConceptTransitiveNarrowers($request->getUri(), $this->parseLimit(), $request->getLang());
681
        if (empty($narrowers)) {
682
            return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
683
        }
684
685
        foreach ($narrowers as $nuri => $vals) {
686
            $result = array('uri' => $nuri, 'prefLabel' => $vals['label']);
687
            if (isset($vals['direct'])) {
688
                $result['narrower'] = $vals['direct'];
689
            }
690
            $results[$nuri] = $result;
691
        }
692
693
        $ret = array_merge_recursive($this->context, array(
694
            '@context' => array('prefLabel' => 'skos:prefLabel', 'narrower' => array('@id' => 'skos:narrower', '@type' => '@id'), 'narrowerTransitive' => array('@id' => 'skos:narrowerTransitive', '@container' => '@index'), '@language' => $request->getLang()),
695
            'uri' => $request->getUri(),
696
            'narrowerTransitive' => $results)
697
        );
698
699
        return $this->returnJson($ret);
700
    }
701
702
    /**
703
     * Used for querying broader transitive relations