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 (#634)
by
unknown
03:03
created

BaseCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 23
c 1
b 0
f 0
dl 0
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSolrCores() 0 22 2
A getSolrCoreUid() 0 8 2
A getStartingPoint() 0 6 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\Command;
14
15
use Symfony\Component\Console\Command\Command;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Core\Utility\MathUtility;
18
use TYPO3\CMS\Core\Database\ConnectionPool;
19
use TYPO3\CMS\Core\Database\Connection;
20
21
/**
22
 * Base class for CLI Command classes.
23
 *
24
 * @author Beatrycze Volk <[email protected]>
25
 * @package TYPO3
26
 * @subpackage dlf
27
 * @access public
28
 */
29
class BaseCommand extends Command
30
{
31
    /**
32
     * Return starting point for indexing command.
33
     *
34
     * @param string|string[]|bool|null $inputPid possible pid
35
     *
36
     * @return int starting point for indexing command
37
     */
38
    protected function getStartingPoint($inputPid): int
39
    {
40
        if (MathUtility::canBeInterpretedAsInteger($inputPid)) {
41
            return MathUtility::forceIntegerInRange((int) $inputPid, 0);
42
        }
43
        return 0;
44
    }
45
46
    /**
47
     * Return matching uid of Solr core depending on the input value.
48
     *
49
     * @param array $solrCores array of the valid Solr cores
50
     * @param string|bool|null $inputSolrId possible uid or name of Solr core
51
     *
52
     * @return int matching uid of Solr core
53
     */
54
    protected function getSolrCoreUid(array $solrCores, $inputSolrId): int
55
    {
56
        if (MathUtility::canBeInterpretedAsInteger($inputSolrId)) {
57
            $solrCoreUid = MathUtility::forceIntegerInRange((int) $inputSolrId, 0);
58
        } else {
59
            $solrCoreUid = $solrCores[$inputSolrId];
60
        }
61
        return $solrCoreUid;
62
    }
63
64
    /**
65
     * Fetches all Solr cores on given page.
66
     *
67
     * @param int $pageId The UID of the Solr core or 0 to disable indexing
68
     *
69
     * @return array Array of valid Solr cores
70
     */
71
    protected function getSolrCores(int $pageId): array
72
    {
73
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
74
            ->getQueryBuilderForTable('tx_dlf_solrcores');
75
76
        $solrCores = [];
77
        $result = $queryBuilder
78
            ->select('uid', 'index_name')
79
            ->from('tx_dlf_solrcores')
80
            ->where(
81
                $queryBuilder->expr()->eq(
82
                    'pid',
83
                    $queryBuilder->createNamedParameter((int) $pageId, Connection::PARAM_INT)
84
                )
85
            )
86
            ->execute();
87
88
        while ($record = $result->fetch()) {
89
            $solrCores[$record['index_name']] = $record['uid'];
90
        }
91
92
        return $solrCores;
93
    }
94
}
95