Passed
Pull Request — master (#90)
by
unknown
03:04
created

GndController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
B searchAction() 0 27 4
A gndAction() 0 7 1
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
    // TODO: Make gndHost and Urls configurable
26
    protected $gndHost = 'https://xgnd.bsz-bw.de/';
27
28
    protected $searchUrl = 'Anfrage?suchfeld=pica.swr&suchfilter=000000&suchoptionen=pica.tbs%3D%22s%22&suchwort=';
29
30
    protected $gndResolverUrl = 'Anfrage?suchfeld=pica.ppn&suchoptionen=pica.tbs%3D"s"+and+&suchwort=';
31
32
    protected $baseGndValueUri = 'http://d-nb.info/gnd/';
33
34
    /**
35
     * @param string $search
36
     * @return array
37
     */
38
    public function searchAction($search) {
39
40
        $url = $this->gndHost . $this->searchUrl . $search;
41
        $content = file_get_contents($url);
42
        $json = json_decode($content);
43
44
        $listArray = array();
45
        $i = 0;
46
        foreach ($json as $value) {
47
            $listArray[$i]['value'] = $value->Ansetzung;
48
            $listArray[$i]['ppn'] = $value->PPN;
49
            $listArray[$i]['typ'] = $value->Typ;
50
            if ($value->GNDNr) {
51
                $listArray[$i]['gnd'] = $this->baseGndValueUri.$value->GNDNr;
52
            } else {
53
                $listArray[$i]['gnd'] = $this->baseGndValueUri.$this->gndAction($value->PPN);
54
            }
55
            $i++;
56
        }
57
58
        if (empty($listArray)) {
59
            echo json_encode(null);
60
        } else {
61
            echo json_encode($listArray);
62
        }
63
64
        return '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the documented return type array.
Loading history...
65
    }
66
67
    /**
68
     * @param string $PPN
69
     * @return mixed
70
     */
71
    public function gndAction($PPN) {
72
73
        $url = $this->gndHost . $this->gndResolverUrl . $PPN;
74
        $content = file_get_contents($url);
75
        $json = json_decode($content);
76
77
        return $json[0]->GNDNr;
78
    }
79
}