Passed
Pull Request — master (#90)
by
unknown
02:11
created

GndController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A searchAction() 0 23 3
1
<?php
2
namespace EWW\Dpf\Controller;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\GeneralUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
/**
21
 * GndController
22
 */
23
class GndController extends \EWW\Dpf\Controller\AbstractController
24
{
25
    protected $gndHost = 'http://lobid.org/gnd/';
26
27
    protected $searchUrl = 'search?format=json:suggest&filter=type:SubjectHeading&size=100&q=';
28
29
    /**
30
     *
31
     * @param string $search
32
     * @return string
33
     */
34
    public function searchAction($search) {
35
36
        $url = $this->gndHost . $this->searchUrl . $search;
37
        $content = file_get_contents($url);
38
        $json = json_decode($content);
39
40
41
        $listArray = array();
42
        $i = 0;
43
        foreach ($json as $value) {
44
            $listArray[$i]['value'] = $value->label;
45
            $listArray[$i]['label'] = htmlentities($value->label);
46
            $listArray[$i]['gnd'] = $value->id;
47
            $i++;
48
        }
49
50
        if (empty($listArray)) {
51
            echo json_encode(null);
52
        } else {
53
            echo json_encode($listArray);
54
        }
55
56
        return '';
57
    }
58
59
}