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 — dev-extbase-fluid (#754)
by Alexander
02:42
created

AbstractController::getParametersSafely()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
4
 *
5
 * This file is part of the Kitodo and TYPO3 projects.
6
 *
7
 * @license GNU General Public License version 3 or later.
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace Kitodo\Dlf\Controller;
13
14
use Kitodo\Dlf\Common\Doc;
15
use Kitodo\Dlf\Common\Helper;
16
use Kitodo\Dlf\Domain\Model\Document;
17
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
18
use Psr\Log\LoggerAwareInterface;
19
use Psr\Log\LoggerAwareTrait;
20
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
21
use TYPO3\CMS\Core\Database\ConnectionPool;
22
use TYPO3\CMS\Core\Localization\LanguageService;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3\CMS\Core\Utility\MathUtility;
25
26
27
/**
28
 *
29
 */
30
abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements LoggerAwareInterface
31
{
32
    use LoggerAwareTrait;
33
34
    /**
35
     * @var DocumentRepository
36
     */
37
    protected $documentRepository;
38
39
    /**
40
     * @param DocumentRepository $documentRepository
41
     */
42
    public function injectDocumentRepository(DocumentRepository $documentRepository)
43
    {
44
        $this->documentRepository = $documentRepository;
45
    }
46
47
    /**
48
     * This holds the current document
49
     *
50
     * @var \Kitodo\Dlf\Domain\Model\Document
51
     * @access protected
52
     */
53
    protected $document;
54
55
    /**
56
     * @var array
57
     * @access protected
58
     */
59
    protected $extConf;
60
61
    /**
62
     * This holds the request parameter
63
     *
64
     * @var array
65
     * @access protected
66
     */
67
    protected $requestData;
68
69
    /**
70
     * This holds some common data for the fluid view
71
     *
72
     * @var array
73
     * @access protected
74
     */
75
    protected $viewData;
76
77
    /**
78
     * Initialize the plugin controller
79
     *
80
     * @access protected
81
     * @return void
82
     */
83
    protected function initialize()
84
    {
85
        $this->requestData = GeneralUtility::_GPmerged('tx_dlf');
86
        if (empty($this->requestData['page'])) {
87
            $this->requestData['page'] = 1;
88
        }
89
        $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0);
90
91
        // Get extension configuration.
92
        $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf');
93
94
        $this->viewData = [
95
            'pageUid' => $GLOBALS['TSFE']->id,
96
            'requestData' => $this->requestData
97
        ];
98
    }
99
100
    /**
101
     * Loads the current document into $this->document
102
     *
103
     * @access protected
104
     *
105
     * @param array $requestData: The request data
106
     *
107
     * @return void
108
     */
109
    protected function loadDocument($requestData)
110
    {
111
        // Try to get document format from database
112
        if (!empty($requestData['id'])) {
113
114
            $doc = null;
115
116
            if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) {
117
                // find document from repository by uid
118
                $this->document = $this->documentRepository->findOneByIdAndSettings((int) $requestData['id']);
119
                if ($this->document) {
120
                    $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true);
121
                } else {
122
                    $this->logger->error('Invalid UID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
123
                }
124
            } else if (GeneralUtility::isValidUrl($requestData['id'])) {
125
126
                $doc = Doc::getInstance($requestData['id'], $this->settings, true);
127
128
                if ($doc !== null) {
129
                    if ($doc->recordId) {
130
                        $this->document = $this->documentRepository->findOneByRecordId($doc->recordId);
0 ignored issues
show
Bug introduced by
The method findOneByRecordId() does not exist on Kitodo\Dlf\Domain\Repository\DocumentRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

130
                        /** @scrutinizer ignore-call */ 
131
                        $this->document = $this->documentRepository->findOneByRecordId($doc->recordId);
Loading history...
131
                    }
132
133
                    if ($this->document === null) {
134
                        // create new dummy Document object
135
                        $this->document = GeneralUtility::makeInstance(Document::class);
136
                    }
137
138
                    $this->document->setLocation($requestData['id']);
139
                } else {
140
                    $this->logger->error('Invalid location given "' . $requestData['id'] . '" for document loading');
141
                }
142
            }
143
144
            if ($this->document !== null && $doc !== null) {
145
                $this->document->setDoc($doc);
146
            }
147
148
        } elseif (!empty($requestData['recordId'])) {
149
150
            $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']);
151
152
            if ($this->document !== null) {
153
                $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true);
0 ignored issues
show
Bug introduced by
The method getLocation() does not exist on TYPO3\CMS\Extbase\Persistence\QueryResultInterface. ( Ignorable by Annotation )

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

153
                $doc = Doc::getInstance($this->document->/** @scrutinizer ignore-call */ getLocation(), $this->settings, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
                if ($this->document !== null && $doc !== null) {
155
                    $this->document->setDoc($doc);
0 ignored issues
show
Bug introduced by
The method setDoc() does not exist on TYPO3\CMS\Extbase\Persistence\QueryResultInterface. ( Ignorable by Annotation )

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

155
                    $this->document->/** @scrutinizer ignore-call */ 
156
                                     setDoc($doc);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
                } else {
157
                    $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"');
158
                }
159
            }
160
        } else {
161
            $this->logger->error('Invalid ID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
162
        }
163
    }
164
165
    /**
166
     * Returns the LanguageService
167
     *
168
     * @return LanguageService
169
     */
170
    protected function getLanguageService(): LanguageService
171
    {
172
        return $GLOBALS['LANG'];
173
    }
174
175
    /**
176
     * Safely gets Parameters from request
177
     * if they exist
178
     *
179
     * @param string $parameterName
180
     *
181
     * @return null|string
182
     */
183
    protected function getParametersSafely($parameterName)
184
    {
185
        if ($this->request->hasArgument($parameterName)) {
186
            return $this->request->getArgument($parameterName);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->request->g...rgument($parameterName) also could return the type array which is incompatible with the documented return type null|string.
Loading history...
187
        }
188
        return null;
189
    }
190
191
    /**
192
     * This is the constructor
193
     *
194
     * @access public
195
     *
196
     * @return void
197
     */
198
    public function __construct()
199
    {
200
        $this->initialize();
201
    }
202
}
203