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

Profile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 4
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 profile API class
22
 **/
23
class Profile
24
{
25
    /**
26
     * This holds the logger
27
     *
28
     * @var LogManager
29
     * @access protected
30
     */
31
    protected $logger;
32
33
    /**
34
     * The raw ORCID profile
35
     *
36
     * @var SimpleXmlElement
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Api\Orcid\SimpleXmlElement was not found. Did you mean SimpleXmlElement? If so, make sure to prefix the type with \.
Loading history...
37
     **/
38
    private $raw = null;
39
40
    /**
41
     * Constructs client instance
42
     *
43
     * @param string $orcid: the ORCID to search for
44
     *
45
     * @return void
46
     **/
47
    public function __construct($orcid)
48
    {
49
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
50
        $this->client = new Client($orcid, GeneralUtility::makeInstance(RequestFactory::class));
0 ignored issues
show
Bug Best Practice introduced by
The property client does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
    }
52
53
    /**
54
     * Get the ORCID profile data
55
     *
56
     * @return object
57
     **/
58
    public function getData()
59
    {
60
        $this->getRaw('person');
61
        if (!empty($this->raw)) {
62
            $data = [];
63
            $data['address'] = $this->getAddress();
64
            $data['email'] = $this->getEmail();
65
            $data['fullName'] = $this->getFullName();
66
            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...
67
        } else {
68
            $this->logger->warning('No data found for given ORCID');
69
            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...
70
        }
71
    }
72
73
    /**
74
     * Get the address
75
     *
76
     * @return string
77
     **/
78
    public function getAddress()
79
    {
80
        $this->getRaw('address');
81
        if (!empty($this->raw)) {
82
            $this->raw->registerXPathNamespace('address', 'http://www.orcid.org/ns/address');
83
            return (string) $this->raw->xpath('./address:address/address:country')[0];
84
        } else {
85
            $this->logger->warning('No address found for given ORCID');
86
            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...
87
        }
88
    }
89
90
    /**
91
     * Get the email
92
     *
93
     * @return string
94
     **/
95
    public function getEmail()
96
    {
97
        $this->getRaw('email');
98
        if (!empty($this->raw)) {
99
            $this->raw->registerXPathNamespace('email', 'http://www.orcid.org/ns/email');
100
            return (string) $this->raw->xpath('./email:email/email:email')[0];
101
        } else {
102
            $this->logger->warning('No email found for given ORCID');
103
            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...
104
        }
105
    }
106
107
    /**
108
     * Get the full name
109
     *
110
     * @return  string
111
     **/
112
    public function getFullName()
113
    {
114
        $this->getRaw('personal-details');
115
        if (!empty($this->raw)) {
116
            $this->raw->registerXPathNamespace('personal-details', 'http://www.orcid.org/ns/personal-details');
117
            $givenNames = $this->raw->xpath('./personal-details:name/personal-details:given-names');
118
            $familyName = $this->raw->xpath('./personal-details:name/personal-details:family-name');
119
            return (string) $givenNames[0] . ' ' . (string) $familyName[0];
120
        } else {
121
            $this->logger->warning('No name found for given ORCID');
122
            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...
123
        }
124
    }
125
126
    /**
127
     * Get the ORCID part of profile data for given endpoint
128
     *
129
     * @param string $endpoint: the endpoint for search URL
130
     *
131
     * @return void
132
     **/
133
    protected function getRaw($endpoint)
134
    {
135
        $this->client->setEndpoint($endpoint);
136
        $data = $this->client->getData();
137
        if (!isset($this->raw) && $data != false) {
138
            $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 Kitodo\Dlf\Api\Orcid\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...
139
        }
140
    }
141
}
142