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 (#899)
by Beatrycze
03:23
created

AbstractController::isDocMissing()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 2
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
 * 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
        return $this->isDocMissing() || $this->document->getDoc()->numPages < 1;
183
    }
184
185
    /**
186
     * Checks if doc is missing
187
     * 
188
     * @return boolean
189
     */
190
    protected function isDocMissing() {
191
        return $this->document === null || $this->document->getDoc() === null;
192
    }
193
194
    /**
195
     * Returns the LanguageService
196
     *
197
     * @return LanguageService
198
     */
199
    protected function getLanguageService(): LanguageService
200
    {
201
        return $GLOBALS['LANG'];
202
    }
203
204
    /**
205
     * Safely gets Parameters from request
206
     * if they exist
207
     *
208
     * @param string $parameterName
209
     *
210
     * @return null|string|array
211
     */
212
    protected function getParametersSafely($parameterName)
213
    {
214
        if ($this->request->hasArgument($parameterName)) {
215
            return $this->request->getArgument($parameterName);
216
        }
217
        return null;
218
    }
219
220
    /**
221
     * This is the constructor
222
     *
223
     * @access public
224
     *
225
     * @return void
226
     */
227
    public function __construct()
228
    {
229
        $this->initialize();
230
    }
231
}
232