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:26
created

Profile   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 41
c 1
b 0
f 0
dl 0
loc 107
rs 10
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullName() 0 11 2
A __construct() 0 3 1
A getAddress() 0 9 2
A getData() 0 12 2
A getRaw() 0 6 3
A getEmail() 0 9 2
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 Psr\Log\LoggerAwareInterface;
17
use Psr\Log\LoggerAwareTrait;
18
use TYPO3\CMS\Core\Http\RequestFactory;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21
/**
22
 * ORCID profile API class
23
 **/
24
class Profile implements LoggerAwareInterface
25
{
26
    use LoggerAwareTrait;
27
28
    /**
29
     * The raw ORCID profile
30
     *
31
     * @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...
32
     **/
33
    private $raw = null;
34
35
    /**
36
     * Constructs client instance
37
     *
38
     * @param string $orcid: the ORCID to search for
39
     *
40
     * @return void
41
     **/
42
    public function __construct($orcid)
43
    {
44
        $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...
45
    }
46
47
    /**
48
     * Get the ORCID profile data
49
     *
50
     * @return  object
51
     **/
52
    public function getData()
53
    {
54
        $this->getRaw('person');
55
        if (!empty($this->raw)) {
56
            $data = [];
57
            $data['address'] = $this->getAddress();
58
            $data['email'] = $this->getEmail();
59
            $data['fullName'] = $this->getFullName();
60
            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...
61
        } else {
62
            $this->logger->warning('No data found for given ORCID');
63
            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...
64
        }
65
    }
66
67
    /**
68
     * Get the address
69
     * 
70
     * @return  string
71
     **/
72
    public function getAddress()
73
    {
74
        $this->getRaw('address');
75
        if (!empty($this->raw)) {
76
            $this->raw->registerXPathNamespace('address', 'http://www.orcid.org/ns/address');
77
            return (string) $this->raw->xpath('./address:address/address:country')[0];
78
        } else {
79
            $this->logger->warning('No address found for given ORCID');
80
            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...
81
        }
82
    }
83
84
    /**
85
     * Get the email
86
     * 
87
     * @return  string
88
     **/
89
    public function getEmail()
90
    {
91
        $this->getRaw('email');
92
        if (!empty($this->raw)) {
93
            $this->raw->registerXPathNamespace('email', 'http://www.orcid.org/ns/email');
94
            return (string) $this->raw->xpath('./email:email/email:email')[0];
95
        } else {
96
            $this->logger->warning('No email found for given ORCID');
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('personal-details');
109
        if (!empty($this->raw)) {
110
            $this->raw->registerXPathNamespace('personal-details', 'http://www.orcid.org/ns/personal-details');
111
            $givenNames = $this->raw->xpath('./personal-details:name/personal-details:given-names');
112
            $familyName = $this->raw->xpath('./personal-details:name/personal-details:family-name');
113
            return (string) $givenNames[0] . ' ' . (string) $familyName[0];
114
        } else {
115
            $this->logger->warning('No name found for given ORCID');
116
            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...
117
        }
118
    }
119
120
    /**
121
     * Get the ORCID part of profile data for given endpoint
122
     *
123
     * @return void
124
     **/
125
    protected function getRaw($endpoint)
126
    {
127
        $this->client->setEndpoint($endpoint);
128
        $data = $this->client->getData();
129
        if (!isset($this->raw) && $data != false) {
130
            $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...
131
        }
132
    }
133
}
134