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 (#885)
by
unknown
08:49
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\Domain\Model\Document;
16
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
17
use Psr\Log\LoggerAwareInterface;
18
use Psr\Log\LoggerAwareTrait;
19
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
20
use TYPO3\CMS\Core\Localization\LanguageService;
21
use TYPO3\CMS\Core\Pagination\PaginationInterface;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use TYPO3\CMS\Core\Utility\MathUtility;
24
use TYPO3\CMS\Core\Pagination\PaginatorInterface;
25
26
27
/**
28
 * Abstract controller class for most of the plugin controller.
29
 *
30
 * @author Sebastian Meyer <[email protected]>
31
 * @package TYPO3
32
 * @subpackage dlf
33
 * @access public
34
 */
35
abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements LoggerAwareInterface
36
{
37
    use LoggerAwareTrait;
38
39
    /**
40
     * @var DocumentRepository
41
     */
42
    protected $documentRepository;
43
44
    /**
45
     * @param DocumentRepository $documentRepository
46
     */
47
    public function injectDocumentRepository(DocumentRepository $documentRepository)
48
    {
49
        $this->documentRepository = $documentRepository;
50
    }
51
52
    /**
53
     * This holds the current document
54
     *
55
     * @var \Kitodo\Dlf\Domain\Model\Document
56
     * @access protected
57
     */
58
    protected $document;
59
60
    /**
61
     * @var array
62
     * @access protected
63
     */
64
    protected $extConf;
65
66
    /**
67
     * This holds the request parameter
68
     *
69
     * @var array
70
     * @access protected
71
     */
72
    protected $requestData;
73
74
    /**
75
     * This holds some common data for the fluid view
76
     *
77
     * @var array
78
     * @access protected
79
     */
80
    protected $viewData;
81
82
    /**
83
     * Initialize the plugin controller
84
     *
85
     * @access protected
86
     * @return void
87
     */
88
    protected function initialize()
89
    {
90
        $this->requestData = GeneralUtility::_GPmerged('tx_dlf');
91
        if (empty($this->requestData['page'])) {
92
            $this->requestData['page'] = 1;
93
        }
94
        $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0);
95
96
        // Get extension configuration.
97
        $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf');
98
99
        $this->viewData = [
100
            'pageUid' => $GLOBALS['TSFE']->id,
101
            'uniqueId'=> uniqid(),
102
            'requestData' => $this->requestData
103
        ];
104
    }
105
106
    /**
107
     * Loads the current document into $this->document
108
     *
109
     * @access protected
110
     *
111
     * @param array $requestData: The request data
112
     *
113
     * @return void
114
     */
115
    protected function loadDocument($requestData)
116
    {
117
        // Try to get document format from database
118
        if (!empty($requestData['id'])) {
119
120
            $doc = null;
121
122
            if (MathUtility::canBeInterpretedAsInteger($requestData['id'])) {
123
                // find document from repository by uid
124
                $this->document = $this->documentRepository->findOneByIdAndSettings((int) $requestData['id']);
125
                if ($this->document) {
126
                    $doc = Doc::getInstance($this->document->getLocation(), $this->settings, true);
127
                } else {
128
                    $this->logger->error('Invalid UID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
129
                }
130
            } else if (GeneralUtility::isValidUrl($requestData['id'])) {
131
132
                $doc = Doc::getInstance($requestData['id'], $this->settings, true);
133
134
                if ($doc !== null) {
135
                    if ($doc->recordId) {
136
                        $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

136
                        /** @scrutinizer ignore-call */ 
137
                        $this->document = $this->documentRepository->findOneByRecordId($doc->recordId);
Loading history...
137
                    }
138
139
                    if ($this->document === null) {
140
                        // create new dummy Document object
141
                        $this->document = GeneralUtility::makeInstance(Document::class);
142
                    }
143
144
                    // Make sure configuration PID is set when applicable
145
                    if ($doc->cPid == 0) {
146
                        $doc->cPid = max(intval($this->settings['storagePid']), 0);
147
                    }
148
149
                    $this->document->setLocation($requestData['id']);
150
                } else {
151
                    $this->logger->error('Invalid location given "' . $requestData['id'] . '" for document loading');
152
                }
153
            }
154
155
            if ($this->document !== null && $doc !== null) {
156
                $this->document->setDoc($doc);
157
            }
158
159
        } elseif (!empty($requestData['recordId'])) {
160
161
            $this->document = $this->documentRepository->findOneByRecordId($requestData['recordId']);
162
163
            if ($this->document !== null) {
164
                $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

164
                $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...
165
                if ($this->document !== null && $doc !== null) {
166
                    $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

166
                    $this->document->/** @scrutinizer ignore-call */ 
167
                                     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...
167
                } else {
168
                    $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"');
169
                }
170
            }
171
        } else {
172
            $this->logger->error('Invalid ID "' . $requestData['id'] . '" or PID "' . $this->settings['storagePid'] . '" for document loading');
173
        }
174
    }
175
176
    /**
177
     * Returns the LanguageService
178
     *
179
     * @return LanguageService
180
     */
181
    protected function getLanguageService(): LanguageService
182
    {
183
        return $GLOBALS['LANG'];
184
    }
185
186
    /**
187
     * Safely gets Parameters from request
188
     * if they exist
189
     *
190
     * @param string $parameterName
191
     *
192
     * @return null|string|array
193
     */
194
    protected function getParametersSafely($parameterName)
195
    {
196
        if ($this->request->hasArgument($parameterName)) {
197
            return $this->request->getArgument($parameterName);
198
        }
199
        return null;
200
    }
201
202
    /**
203
     * This is the constructor
204
     *
205
     * @access public
206
     *
207
     * @return void
208
     */
209
    public function __construct()
210
    {
211
        $this->initialize();
212
    }
213
214
    /**
215
     * build simple pagination
216
     *
217
     * @param PaginationInterface $pagination
218
     * @param PaginatorInterface $paginator
219
     * @return array
220
     */
221
    protected function buildSimplePagination(PaginationInterface $pagination, PaginatorInterface $paginator)
222
    {
223
        $firstPage = $pagination->getFirstPageNumber();
224
        $lastPage = $pagination->getLastPageNumber();
225
226
        return [
227
            'lastPageNumber' => $lastPage,
228
            'firstPageNumber' => $firstPage,
229
            'nextPageNumber' => ($pagination->getNextPageNumber()),
230
            'previousPageNumber' => $pagination->getPreviousPageNumber(),
231
            'startRecordNumber' => $pagination->getStartRecordNumber(),
232
            'endRecordNumber' => $pagination->getEndRecordNumber(),
233
            'currentPageNumber' => $paginator->getCurrentPageNumber(),
234
            'pages' => range($firstPage, $lastPage)
235
        ];
236
    }
237
}
238