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:26
created

AbstractController   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 220
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 67
c 2
b 0
f 0
dl 0
loc 220
rs 10
wmc 27

9 Methods

Rating   Name   Duplication   Size   Complexity  
A injectDocumentRepository() 0 3 1
C loadDocument() 0 58 15
A initialize() 0 15 2
A __construct() 0 3 1
A isDocMissingOrEmpty() 0 3 2
A getParametersSafely() 0 6 2
A isDocMissing() 0 3 2
A getLanguageService() 0 3 1
A buildSimplePagination() 0 14 1
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
     * Checks if doc is missing or is empty (no pages)
178
     *
179
     * @return boolean
180
     */
181
    protected function isDocMissingOrEmpty()
182
    {
183
        return $this->isDocMissing() || $this->document->getDoc()->numPages < 1;
184
    }
185
186
    /**
187
     * Checks if doc is missing
188
     *
189
     * @return boolean
190
     */
191
    protected function isDocMissing()
192
    {
193
        return $this->document === null || $this->document->getDoc() === null;
194
    }
195
196
    /**
197
     * Returns the LanguageService
198
     *
199
     * @return LanguageService
200
     */
201
    protected function getLanguageService(): LanguageService
202
    {
203
        return $GLOBALS['LANG'];
204
    }
205
206
    /**
207
     * Safely gets Parameters from request
208
     * if they exist
209
     *
210
     * @param string $parameterName
211
     *
212
     * @return null|string|array
213
     */
214
    protected function getParametersSafely($parameterName)
215
    {
216
        if ($this->request->hasArgument($parameterName)) {
217
            return $this->request->getArgument($parameterName);
218
        }
219
        return null;
220
    }
221
222
    /**
223
     * This is the constructor
224
     *
225
     * @access public
226
     *
227
     * @return void
228
     */
229
    public function __construct()
230
    {
231
        $this->initialize();
232
    }
233
234
    /**
235
     * build simple pagination
236
     *
237
     * @param PaginationInterface $pagination
238
     * @param PaginatorInterface $paginator
239
     * @return array
240
     */
241
    protected function buildSimplePagination(PaginationInterface $pagination, PaginatorInterface $paginator)
242
    {
243
        $firstPage = $pagination->getFirstPageNumber();
244
        $lastPage = $pagination->getLastPageNumber();
245
246
        return [
247
            'lastPageNumber' => $lastPage,
248
            'firstPageNumber' => $firstPage,
249
            'nextPageNumber' => ($pagination->getNextPageNumber()),
250
            'previousPageNumber' => $pagination->getPreviousPageNumber(),
251
            'startRecordNumber' => $pagination->getStartRecordNumber(),
252
            'endRecordNumber' => $pagination->getEndRecordNumber(),
253
            'currentPageNumber' => $paginator->getCurrentPageNumber(),
254
            'pages' => range($firstPage, $lastPage)
255
        ];
256
    }
257
}
258