Skip to content

Commit

Permalink
Merge remote-tracking branch 'kitodo/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
csidirop committed Dec 8, 2023
2 parents 948ac16 + 10248c5 commit 912664d
Show file tree
Hide file tree
Showing 170 changed files with 6,516 additions and 3,198 deletions.
31 changes: 31 additions & 0 deletions .github/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
ignoreErrors:
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::countByPid\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findByIsListed\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findByIsSortable\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByFeUserId\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByIndexName\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByPid\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByRecordId\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByRoot\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneBySessionId\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByType\(\)\.#'
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByUid\(\)\.#'
- '#Call to an undefined method Psr\\Http\\Message\\RequestFactoryInterface::request\(\)\.#'
- '#Call to an undefined method Solarium\\Core\\Query\\DocumentInterface::setField\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getHeight\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getWidth\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getPossibleTextAnnotationContainers\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getTextAnnotations\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\ManifestInterface::getOriginalJsonArray\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\RangeInterface::getMemberRangesAndRanges\(\)\.#'
- '#Constant LOG_SEVERITY_ERROR not found\.#'
- '#Constant LOG_SEVERITY_NOTICE not found\.#'
- '#Constant LOG_SEVERITY_WARNING not found\.#'
- '#Constant TYPO3_MODE not found\.#'
level: 5
paths:
- ../Classes/
excludePaths:
- ../Classes/Controller/OaiPmhController.php
treatPhpDocTypesAsCertain: false
25 changes: 25 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PHPStan

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
uses: php-actions/composer@v6
with:
command: update
php_version: "7.4"

- name: PHPStan Static Analysis
uses: php-actions/phpstan@v3
with:
configuration: ./.github/phpstan.neon
65 changes: 36 additions & 29 deletions Classes/Api/Orcid/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,63 +21,64 @@
/**
* ORCID API Client class
*
* @author Beatrycze Volk <[email protected]>
* @package TYPO3
* @subpackage dlf
*
* @access public
**/
class Client
{
/**
* constants for API endpoint
* @var string constant for API hostname
**/
const HOSTNAME = 'orcid.org';
const VERSION = '3.0';
const HOSTNAME = 'orcid.org';

/**
* @var string constant for API version
**/
const VERSION = '3.0';

/**
* This holds the logger
*
* @var Logger
* @access protected
* @var Logger This holds the logger
*/
protected $logger;
protected Logger $logger;

/**
* The ORCID API endpoint
*
* @var string
* @access private
* @var string The ORCID API endpoint
**/
private $endpoint = 'record';
private string $endpoint = 'record';

/**
* The ORCID API access level
*
* @var string
* @access private
* @var string The ORCID API access level
**/
private $level = 'pub';
private string $level = 'pub';

/**
* The ORCID ID to search for
*
* @var string
* @access private
* @var string The ORCID ID to search for
**/
private $orcid = null;
private string $orcid;

/**
* The request object
*
* @var RequestFactoryInterface
* @access private
* @var RequestFactoryInterface The request object
**/
private $requestFactory = null;
private RequestFactoryInterface $requestFactory;

/**
* Constructs a new instance
*
* @param string $orcid: the ORCID to search for
* @access public
*
* @param string $orcid the ORCID to search for
* @param RequestFactory $requestFactory a request object to inject
*
* @return void
**/
public function __construct($orcid, RequestFactory $requestFactory)
public function __construct(string $orcid, RequestFactory $requestFactory)
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
$this->orcid = $orcid;
Expand All @@ -87,17 +88,21 @@ public function __construct($orcid, RequestFactory $requestFactory)
/**
* Sets API endpoint
*
* @param string $endpoint the shortname of the endpoint
* @access public
*
* @param string $endpoint the shortname of the endpoint
*
* @return void
*/
public function setEndpoint($endpoint) {
public function setEndpoint(string $endpoint): void {
$this->endpoint = $endpoint;
}

/**
* Get the profile data
*
* @access public
*
* @return object|bool
**/
public function getData()
Expand All @@ -115,9 +120,11 @@ public function getData()
/**
* Creates the qualified API endpoint for retrieving the desired data
*
* @access private
*
* @return string
**/
private function getApiEndpoint()
private function getApiEndpoint(): string
{
$url = 'https://' . $this->level . '.' . self::HOSTNAME;
$url .= '/v' . self::VERSION . '/';
Expand Down
51 changes: 29 additions & 22 deletions Classes/Api/Orcid/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,41 @@
/**
* ORCID API Profile class
*
* @author Beatrycze Volk <[email protected]>
* @package TYPO3
* @subpackage dlf
*
* @access public
**/
class Profile
{
/**
* This holds the logger
*
* @var Logger
* @access protected
* @var Logger This holds the logger
*/
protected $logger;
protected Logger $logger;

/**
* This holds the client
*
* @var Client
* @access protected
* @access private
* @var Client This holds the client
*/
protected $client;
private Client $client;

/**
* The raw ORCID profile
*
* @var \SimpleXmlElement|false
* @access private
* @var \SimpleXmlElement|false The raw ORCID profile
**/
private $raw = null;
private $raw = false;

/**
* Constructs client instance
*
* @access public
*
* @param string $orcid: the ORCID to search for
*
* @return void
**/
public function __construct($orcid)
public function __construct(string $orcid)
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
$this->client = new Client($orcid, GeneralUtility::makeInstance(RequestFactory::class));
Expand All @@ -67,12 +64,14 @@ public function __construct($orcid)
/**
* Get the ORCID profile data
*
* @access public
*
* @return array|false
**/
public function getData()
{
$this->getRaw('person');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$data = [];
$data['address'] = $this->getAddress();
$data['email'] = $this->getEmail();
Expand All @@ -87,12 +86,14 @@ public function getData()
/**
* Get the address
*
* @access public
*
* @return string|false
**/
public function getAddress()
{
$this->getRaw('address');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$this->raw->registerXPathNamespace('address', 'http://www.orcid.org/ns/address');
return (string) $this->raw->xpath('./address:address/address:country')[0];
} else {
Expand All @@ -104,12 +105,14 @@ public function getAddress()
/**
* Get the email
*
* @access public
*
* @return string|false
**/
public function getEmail()
{
$this->getRaw('email');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$this->raw->registerXPathNamespace('email', 'http://www.orcid.org/ns/email');
return (string) $this->raw->xpath('./email:email/email:email')[0];
} else {
Expand All @@ -121,12 +124,14 @@ public function getEmail()
/**
* Get the full name
*
* @access public
*
* @return string|false
**/
public function getFullName()
{
$this->getRaw('personal-details');
if (!empty($this->raw)) {
if ($this->raw !== false && !empty($this->raw)) {
$this->raw->registerXPathNamespace('personal-details', 'http://www.orcid.org/ns/personal-details');
$givenNames = $this->raw->xpath('./personal-details:name/personal-details:given-names');
$familyName = $this->raw->xpath('./personal-details:name/personal-details:family-name');
Expand All @@ -140,15 +145,17 @@ public function getFullName()
/**
* Get the ORCID part of profile data for given endpoint
*
* @param string $endpoint the shortname of the endpoint
* @access private
*
* @param string $endpoint the shortname of the endpoint
*
* @return void
**/
protected function getRaw($endpoint)
private function getRaw(string $endpoint): void
{
$this->client->setEndpoint($endpoint);
$data = $this->client->getData();
if (!isset($this->raw) && $data != false) {
if ($data != false) {
$this->raw = Helper::getXmlFileAsString($data);
}
}
Expand Down
Loading

0 comments on commit 912664d

Please sign in to comment.