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
Push — master ( 1f4a32...bc6252 )
by
unknown
03:38
created

KitodoProductionHacks::postProcessRecordId()   B

Complexity

Conditions 10
Paths 26

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 19
nc 26
nop 2
dl 0
loc 27
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Hooks;
14
15
/**
16
 * Hooks and hacks for Kitodo.Production
17
 *
18
 * @package TYPO3
19
 * @subpackage dlf
20
 *
21
 * @access public
22
 */
23
class KitodoProductionHacks
24
{
25
    /**
26
     * Hook for \Kitodo\Dlf\Common\MetsDocument::establishRecordId()
27
     * When using Kitodo.Production the record identifier is saved only in MODS, but not
28
     * in METS. To get it anyway, we have to do some magic.
29
     *
30
     * @access public
31
     *
32
     * @param \SimpleXMLElement &$xml The XML object
33
     * @param mixed $recordId The record identifier
34
     *
35
     * @return void
36
     */
37
    public function postProcessRecordId(\SimpleXMLElement &$xml, &$recordId): void
38
    {
39
        if (!$recordId) {
40
            $xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
41
            // Get all logical structure nodes with metadata, but without associated METS-Pointers.
42
            if (($divs = $xml->xpath('//mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]'))) {
43
                $smLinks = $xml->xpath('//mets:structLink/mets:smLink');
44
                if (!empty($smLinks)) {
45
                    foreach ($smLinks as $smLink) {
46
                        $links[(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to;
47
                    }
48
                    foreach ($divs as $div) {
49
                        if (!empty($links[(string) $div['ID']])) {
50
                            $id = (string) $div['DMDID'];
51
                            break;
52
                        }
53
                    }
54
                }
55
                if (empty($id)) {
56
                    $id = (string) $divs[0]['DMDID'];
57
                }
58
                $dmdIds = explode(' ', $id);
59
                foreach ($dmdIds as $dmdId) {
60
                    $recordIds = $xml->xpath('//mets:dmdSec[@ID="' . $dmdId . '"]//mods:mods/mods:recordInfo/mods:recordIdentifier');
61
                    if (!empty($recordIds)) {
62
                        $recordId = (string) $recordIds[0];
63
                        break;
64
                    }
65
                }
66
            }
67
        }
68
    }
69
}
70