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 (#838)
by Beatrycze
03:09
created

OrcidProfile::getAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
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\Orcid;
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
 * ORCID API Profile class
22
 *
23
 * @author Beatrycze Volk <[email protected]>
24
 * @package TYPO3
25
 * @subpackage dlf
26
 * @access public
27
 **/
28
class OrcidProfile
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 OrcidClient
42
     * @access protected
43
     */
44
    protected $client;
45
46
    /**
47
     * The raw ORCID profile
48
     *
49
     * @var \SimpleXmlElement
50
     **/
51
    private $raw = null;
52
53
    /**
54
     * Constructs client instance
55
     *
56
     * @param string $orcid: the ORCID to search for
57
     *
58
     * @return void
59
     **/
60
    public function __construct($orcid)
61
    {
62
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
63
        $this->client = new OrcidClient($orcid, GeneralUtility::makeInstance(RequestFactory::class));
64
    }
65
66
    /**
67
     * Get the ORCID profile data
68
     *
69
     * @return  array|bool
70
     **/
71
    public function getData()
72
    {
73
        $this->getRaw('person');
74
        if (!empty($this->raw)) {
75
            $data = [];
76
            $data['address'] = $this->getAddress();
77
            $data['email'] = $this->getEmail();
78
            $data['fullName'] = $this->getFullName();
79
            return $data;
80
        } else {
81
            $this->logger->warning('No data found for given ORCID');
82
            return false;
83
        }
84
    }
85
86
    /**
87
     * Get the address
88
     *
89
     * @return  string|bool
90
     **/
91
    public function getAddress()
92
    {
93
        $this->getRaw('address');
94
        if (!empty($this->raw)) {
95
            $this->raw->registerXPathNamespace('address', 'http://www.orcid.org/ns/address');
96
            return (string) $this->raw->xpath('./address:address/address:country')[0];
97
        } else {
98
            $this->logger->warning('No address found for given ORCID');
99
            return false;
100
        }
101
    }
102
103
    /**
104
     * Get the email
105
     *
106
     * @return  string|bool
107
     **/
108
    public function getEmail()
109
    {
110
        $this->getRaw('email');
111
        if (!empty($this->raw)) {
112
            $this->raw->registerXPathNamespace('email', 'http://www.orcid.org/ns/email');
113
            return (string) $this->raw->xpath('./email:email/email:email')[0];
114
        } else {
115
            $this->logger->warning('No email found for given ORCID');
116
            return false;
117
        }
118
    }
119
120
    /**
121
     * Get the full name
122
     *
123
     * @return  string|bool
124
     **/
125
    public function getFullName()
126
    {
127
        $this->getRaw('personal-details');
128
        if (!empty($this->raw)) {
129
            $this->raw->registerXPathNamespace('personal-details', 'http://www.orcid.org/ns/personal-details');
130
            $givenNames = $this->raw->xpath('./personal-details:name/personal-details:given-names');
131
            $familyName = $this->raw->xpath('./personal-details:name/personal-details:family-name');
132
            return (string) $givenNames[0] . ' ' . (string) $familyName[0];
133
        } else {
134
            $this->logger->warning('No name found for given ORCID');
135
            return false;
136
        }
137
    }
138
139
    /**
140
     * Get the ORCID part of profile data for given endpoint
141
     *
142
     * @return void
143
     **/
144
    protected function getRaw($endpoint)
145
    {
146
        $this->client->setEndpoint($endpoint);
147
        $data = $this->client->getData();
148
        if (!isset($this->raw) && $data != false) {
149
            $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...
150
        }
151
    }
152
}
153