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

OrcidClient::getApiEndpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
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 Psr\Http\Message\RequestFactoryInterface;
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 Client class
22
 *
23
 * @author Beatrycze Volk <[email protected]>
24
 * @package TYPO3
25
 * @subpackage dlf
26
 * @access public
27
 **/
28
class OrcidClient
29
{
30
    /**
31
     * constants for API endpoint
32
     **/
33
    const HOSTNAME  = 'orcid.org';
34
    const VERSION   = '3.0';
35
36
    /**
37
     * This holds the logger
38
     *
39
     * @var LogManager
40
     * @access protected
41
     */
42
    protected $logger;
43
44
    /**
45
     * The ORCID API endpoint
46
     *
47
     * @var string
48
     **/
49
    private $endpoint = 'record';
50
51
    /**
52
     * The ORCID API access level
53
     *
54
     * @var string
55
     **/
56
    private $level = 'pub';
57
58
    /**
59
     * The login/registration page ORCID
60
     *
61
     * @var string
62
     **/
63
    private $orcid = null;
64
65
    /**
66
     * The request object
67
     *
68
     * @var RequestFactoryInterface
69
     **/
70
    private $requestFactory = null;
71
72
    /**
73
     * Constructs a new instance
74
     *
75
     * @param string $orcid: the ORCID to search for
76
     * @param RequestFactory $requestFactory a request object to inject
77
     * @return void
78
     **/
79
    public function __construct($orcid, RequestFactory $requestFactory)
80
    {
81
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
82
        $this->orcid = $orcid;
83
        $this->requestFactory = $requestFactory;
84
    }
85
86
    /**
87
     * @param string  $endpoint the shortname of the endpoint
88
     */
89
    public function setEndpoint($endpoint) {
90
        $this->endpoint = $endpoint;
91
    }
92
93
    /**
94
     * Get the profile data
95
     *
96
     * @return object|bool
97
     **/
98
    public function getData()
99
    {
100
        $url = $this->getApiEndpoint();
101
        try {
102
            $response = $this->requestFactory->request($url);
103
        } catch (\Exception $e) {
104
            $this->logger->warning('Could not fetch data from URL "' . $url . '". Error: ' . $e->getMessage() . '.');
105
            return false;
106
        }
107
        return $response->getBody()->getContents();
108
    }
109
110
    /**
111
     * Creates the qualified API endpoint for retrieving the desired data
112
     *
113
     * @param string  $endpoint the shortname of the endpoint
114
     * @return string
115
     **/
116
    private function getApiEndpoint()
117
    {
118
        $url  = 'https://' . $this->level . '.' . self::HOSTNAME;
119
        $url .= '/v' . self::VERSION . '/';
120
        $url .= $this->orcid;
121
        $url .= '/' . $this->endpoint;
122
        return $url;
123
    }
124
}
125