Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#834)
by Beatrycze
03:26
created

Profile::getRaw()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Api\Viaf;
14
15
use Kitodo\Dlf\Common\Helper;
16
use TYPO3\CMS\Core\Http\RequestFactory;
17
use TYPO3\CMS\Core\Log\LogManager;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20
/**
21
 * VIAF API Profile class
22
 *
23
 * @author Beatrycze Volk <[email protected]>
24
 * @package TYPO3
25
 * @subpackage dlf
26
 * @access public
27
 **/
28
class Profile
29
{
30
    /**
31
     * This holds the logger
32
     *
33
     * @var LogManager
34
     * @access protected
35
     */
36
    protected $logger;
37
38
    /**
39
     * This holds the client
40
     *
41
     * @var Client
42
     * @access protected
43
     */
44
    protected $client;
45
46
    /**
47
     * The raw VIAF profile
48
     *
49
     * @var \SimpleXmlElement
50
     **/
51
    private $raw = null;
52
53
    /**
54
     * Constructs client instance
55
     *
56
     * @param string $viaf: the VIAF identifier of the profile
57
     *
58
     * @return void
59
     **/
60
    public function __construct($viaf)
61
    {
62
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
63
        $this->client = new Client($viaf, GeneralUtility::makeInstance(RequestFactory::class));
64
    }
65
66
    /**
67
     * Get the VIAF profile data
68
     *
69
     * @return  object
70
     **/
71
    public function getData()
72
    {
73
        $this->getRaw();
74
        if (!empty($this->raw)) {
75
            $data = [];
76
            $data['address'] = $this->getAddress();
77
            $data['fullName'] = $this->getFullName();
78
            return $data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $data returns the type array which is incompatible with the documented return type object.
Loading history...
79
        } else {
80
            $this->logger->warning('No data found for given VIAF URL');
81
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type object.
Loading history...
82
        }
83
    }
84
85
    /**
86
     * Get the address
87
     *
88
     * @return  string
89
     **/
90
    public function getAddress()
91
    {
92
        $this->getRaw();
93
        if (!empty($this->raw->asXML())) {
94
            return (string) $this->raw->xpath('./ns1:nationalityOfEntity/ns1:data/ns1:text')[0];
95
        } else {
96
            $this->logger->warning('No address found for given VIAF URL');
97
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
98
        }
99
    }
100
101
    /**
102
     * Get the full name
103
     *
104
     * @return  string
105
     **/
106
    public function getFullName()
107
    {
108
        $this->getRaw();
109
        if (!empty($this->raw->asXML())) {
110
            $name = $this->raw->xpath('./ns1:mainHeadings/ns1:data/ns1:text');
111
            return (string) $name[0];
112
        } else {
113
            $this->logger->warning('No name found for given VIAF URL');
114
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
115
        }
116
    }
117
118
    /**
119
     * Get the VIAF raw profile data
120
     *
121
     * @return void
122
     **/
123
    protected function getRaw()
124
    {
125
        $data = $this->client->getData();
126
        if (!isset($this->raw) && $data != false) {
127
            $this->raw = Helper::getXmlFileAsString($data);
0 ignored issues
show
Documentation Bug introduced by
It seems like Kitodo\Dlf\Common\Helper...tXmlFileAsString($data) of type false is incompatible with the declared type SimpleXmlElement of property $raw.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
128
            $this->raw->registerXPathNamespace('ns1', 'http://viaf.org/viaf/terms#');
129
        }
130
    }
131
}
132