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 ( 27474d...53316b )
by Sebastian
02:38
created

ConfigurationForm::checkCliUserGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 2
dl 0
loc 25
rs 9.7333
c 0
b 0
f 0
1
<?php
2
namespace Kitodo\Dlf\Hooks;
3
4
/**
5
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
6
 *
7
 * This file is part of the Kitodo and TYPO3 projects.
8
 *
9
 * @license GNU General Public License version 3 or later.
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 */
13
14
use Kitodo\Dlf\Common\Helper;
15
use Kitodo\Dlf\Common\Solr;
16
17
/**
18
 * Hooks and helper for \TYPO3\CMS\Core\TypoScript\ConfigurationForm
19
 *
20
 * @author Sebastian Meyer <[email protected]>
21
 * @package TYPO3
22
 * @subpackage dlf
23
 * @access public
24
 */
25
class ConfigurationForm {
26
    /**
27
     * This holds the current configuration
28
     *
29
     * @var array
30
     * @access protected
31
     */
32
    protected $conf = [];
33
34
    /**
35
     * Check if a connection to a Solr server could be established with the given credentials.
36
     *
37
     * @access public
38
     *
39
     * @param array &$params: An array with parameters
40
     * @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
41
     *
42
     * @return string Message informing the user of success or failure
43
     */
44
    public function checkSolrConnection(&$params, &$pObj) {
2 ignored issues
show
Unused Code introduced by
The parameter $pObj is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    public function checkSolrConnection(&$params, /** @scrutinizer ignore-unused */ &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    public function checkSolrConnection(/** @scrutinizer ignore-unused */ &$params, &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
        $solrInfo = Solr::getSolrConnectionInfo();
46
        // Prepend username and password to hostname.
47
        if (!empty($solrInfo['username'])
48
            && !empty($solrInfo['password'])) {
49
            $host = $solrInfo['username'].':'.$solrInfo['password'].'@'.$solrInfo['host'];
50
        } else {
51
            $host = $solrInfo['host'];
52
        }
53
        // Build request URI.
54
        $url = $solrInfo['scheme'].'://'.$host.':'.$solrInfo['port'].'/'.$solrInfo['path'].'/admin/cores?wt=xml';
55
        $context = stream_context_create([
56
            'http' => [
57
                'method' => 'GET',
58
                'user_agent' => (!empty($this->conf['useragent']) ? $this->conf['useragent'] : ini_get('user_agent'))
59
            ]
60
        ]);
61
        // Try to connect to Solr server.
62
        $response = @simplexml_load_string(file_get_contents($url, FALSE, $context));
63
        // Check status code.
64
        if ($response) {
65
            $status = $response->xpath('//lst[@name="responseHeader"]/int[@name="status"]');
66
            if (is_array($status)) {
1 ignored issue
show
introduced by
The condition is_array($status) is always true.
Loading history...
67
                Helper::addMessage(
68
                    sprintf($GLOBALS['LANG']->getLL('solr.status'), (string) $status[0]),
69
                    $GLOBALS['LANG']->getLL('solr.connected'),
70
                    ($status[0] == 0 ? \TYPO3\CMS\Core\Messaging\FlashMessage::OK : \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING)
1 ignored issue
show
introduced by
The condition $status[0] == 0 is always false.
Loading history...
71
                );
72
                return Helper::renderFlashMessages();
73
            }
74
        }
75
        Helper::addMessage(
76
            sprintf($GLOBALS['LANG']->getLL('solr.error'), $url),
77
            $GLOBALS['LANG']->getLL('solr.notConnected'),
78
            \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
79
        );
80
        return Helper::renderFlashMessages();
81
    }
82
83
    /**
84
     * Make sure a CLI dispatcher is available.
85
     *
86
     * @access public
87
     *
88
     * @param array &$params: An array with parameters
89
     * @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
90
     *
91
     * @return string Message informing the user of success or failure
92
     */
93
    public function checkCliDispatcher(&$params, &$pObj) {
0 ignored issues
show
Unused Code introduced by
The parameter $pObj is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

93
    public function checkCliDispatcher(&$params, /** @scrutinizer ignore-unused */ &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

93
    public function checkCliDispatcher(/** @scrutinizer ignore-unused */ &$params, &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
        // Check if CLI dispatcher is executable.
95
        if (is_executable(PATH_typo3.'cli_dispatch.phpsh')) {
96
            Helper::addMessage(
97
                $GLOBALS['LANG']->getLL('cliDispatcher.cliOkayMsg'),
98
                $GLOBALS['LANG']->getLL('cliDispatcher.cliOkay'),
99
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
100
            );
101
        } else {
102
            Helper::addMessage(
103
                $GLOBALS['LANG']->getLL('cliDispatcher.cliNotOkayMsg'),
104
                $GLOBALS['LANG']->getLL('cliDispatcher.cliNotOkay'),
105
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
106
            );
107
        }
108
        return Helper::renderFlashMessages();
109
    }
110
111
    /**
112
     * Make sure the essential namespaces are defined.
113
     *
114
     * @access public
115
     *
116
     * @param array &$params: An array with parameters
117
     * @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
118
     *
119
     * @return string Message informing the user of success or failure
120
     */
121
    public function checkMetadataFormats(&$params, &$pObj) {
2 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

121
    public function checkMetadataFormats(/** @scrutinizer ignore-unused */ &$params, &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pObj is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

121
    public function checkMetadataFormats(&$params, /** @scrutinizer ignore-unused */ &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
        $nsDefined = [
123
            'MODS' => FALSE,
124
            'TEIHDR' => FALSE,
125
            'ALTO' => FALSE
126
        ];
127
        // Check existing format specifications.
128
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
129
            'type',
130
            'tx_dlf_formats',
131
            '1=1'
132
                .Helper::whereClause('tx_dlf_formats')
133
        );
134
        while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
135
            $nsDefined[$resArray['type']] = TRUE;
136
        }
137
        // Build data array.
138
        $data = [];
139
        // Add MODS namespace.
140
        if (!$nsDefined['MODS']) {
141
            $data['tx_dlf_formats'][uniqid('NEW')] = [
142
                'pid' => 0,
143
                'type' => 'MODS',
144
                'root' => 'mods',
145
                'namespace' => 'http://www.loc.gov/mods/v3',
146
                'class' => 'Kitodo\\\\Dlf\\\\Format\\\\Mods'
147
            ];
148
        }
149
        // Add TEIHDR namespace.
150
        if (!$nsDefined['TEIHDR']) {
151
            $data['tx_dlf_formats'][uniqid('NEW')] = [
152
                'pid' => 0,
153
                'type' => 'TEIHDR',
154
                'root' => 'teiHeader',
155
                'namespace' => 'http://www.tei-c.org/ns/1.0',
156
                'class' => 'Kitodo\\\\Dlf\\\\Format\\\\TeiHeader'
157
            ];
158
        }
159
        // Add ALTO namespace.
160
        if (!$nsDefined['ALTO']) {
161
            $data['tx_dlf_formats'][uniqid('NEW')] = [
162
                'pid' => 0,
163
                'type' => 'ALTO',
164
                'root' => 'alto',
165
                'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#',
166
                'class' => 'Kitodo\\\\Dlf\\\\Format\\\\Alto'
167
            ];
168
        }
169
        if (!empty($data)) {
170
            // Process changes.
171
            $substUid = Helper::processDBasAdmin($data);
172
            if (!empty($substUid)) {
173
                Helper::addMessage(
174
                    $GLOBALS['LANG']->getLL('metadataFormats.nsCreatedMsg'),
175
                    $GLOBALS['LANG']->getLL('metadataFormats.nsCreated'),
176
                    \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
177
                );
178
            } else {
179
                Helper::addMessage(
180
                    $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreatedMsg'),
181
                    $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreated'),
182
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
183
                );
184
            }
185
        } else {
186
            Helper::addMessage(
187
                $GLOBALS['LANG']->getLL('metadataFormats.nsOkayMsg'),
188
                $GLOBALS['LANG']->getLL('metadataFormats.nsOkay'),
189
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
190
            );
191
        }
192
        return Helper::renderFlashMessages();
193
    }
194
195
    /**
196
     * This is the constructor.
197
     *
198
     * @access public
199
     *
200
     * @return void
201
     */
202
    public function __construct() {
203
        // Load localization file.
204
        $GLOBALS['LANG']->includeLLFile('EXT:dlf/Resources/Private/Language/FlashMessages.xml');
205
        // Get current configuration.
206
        $this->conf = array_merge((array) unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']), (array) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('data'));
207
    }
208
}
209