Code Duplication    Length = 24-24 lines in 2 locations

controller/RestController.php 2 locations

@@ 637-660 (lines=24) @@
634
     * @param Request $request
635
     * @return object json-ld wrapped broader transitive concept uris and labels.
636
     */
637
    public function broaderTransitive($request)
638
    {
639
        $results = array();
640
        $broaders = $request->getVocab()->getConceptTransitiveBroaders($request->getUri(), $this->parseLimit(), false, $request->getLang());
641
        if (empty($broaders)) {
642
            return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
643
        }
644
645
        foreach ($broaders as $buri => $vals) {
646
            $result = array('uri' => $buri, 'prefLabel' => $vals['label']);
647
            if (isset($vals['direct'])) {
648
                $result['broader'] = $vals['direct'];
649
            }
650
            $results[$buri] = $result;
651
        }
652
653
        $ret = array_merge_recursive($this->context, array(
654
            '@context' => array('prefLabel' => 'skos:prefLabel', 'broader' => array('@id' => 'skos:broader', '@type' => '@id'), 'broaderTransitive' => array('@id' => 'skos:broaderTransitive', '@container' => '@index'), '@language' => $request->getLang()),
655
            'uri' => $request->getUri(),
656
            'broaderTransitive' => $results)
657
        );
658
659
        return $this->returnJson($ret);
660
    }
661
662
    /**
663
     * Used for querying narrower relations for a concept.
@@ 693-716 (lines=24) @@
690
     * @param Request $request
691
     * @return object json-ld wrapped narrower transitive concept uris and labels.
692
     */
693
    public function narrowerTransitive($request)
694
    {
695
        $results = array();
696
        $narrowers = $request->getVocab()->getConceptTransitiveNarrowers($request->getUri(), $this->parseLimit(), $request->getLang());
697
        if (empty($narrowers)) {
698
            return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
699
        }
700
701
        foreach ($narrowers as $nuri => $vals) {
702
            $result = array('uri' => $nuri, 'prefLabel' => $vals['label']);
703
            if (isset($vals['direct'])) {
704
                $result['narrower'] = $vals['direct'];
705
            }
706
            $results[$nuri] = $result;
707
        }
708
709
        $ret = array_merge_recursive($this->context, array(
710
            '@context' => array('prefLabel' => 'skos:prefLabel', 'narrower' => array('@id' => 'skos:narrower', '@type' => '@id'), 'narrowerTransitive' => array('@id' => 'skos:narrowerTransitive', '@container' => '@index'), '@language' => $request->getLang()),
711
            'uri' => $request->getUri(),
712
            'narrowerTransitive' => $results)
713
        );
714
715
        return $this->returnJson($ret);
716
    }
717
718
    /**
719
     * Used for querying broader transitive relations