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 (#654)
by
unknown
03:00
created

AudioplayerController   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
eloc 69
c 1
b 0
f 0
dl 0
loc 154
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addPlayerJS() 0 23 1
B loadDocument() 0 46 7
B mainAction() 0 43 8
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\Document;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Mvc\Controller\ActionController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use TYPO3\CMS\Core\Page\PageRenderer;
18
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19
use TYPO3\CMS\Core\Utility\MathUtility;
20
use TYPO3\CMS\Core\Utility\PathUtility;
21
22
/**
23
 * Controller for the plugin AudioPlayer for the 'dlf' extension
24
 *
25
 * @author Sebastian Meyer <[email protected]>
26
 * @package TYPO3
27
 * @subpackage dlf
28
 * @access public
29
 */
30
class AudioplayerController extends ActionController
31
{
32
    const PARAMETER_PREFIX = 'tx_dlf';
33
34
    /**
35
     * @var string
36
     */
37
    protected $extKey = 'dlf';
38
39
    /**
40
     * Holds the current audio file's URL, MIME type and optional label
41
     *
42
     * @var array
43
     * @access protected
44
     */
45
    protected $audio = [];
46
47
    /**
48
     * Adds Player javascript
49
     *
50
     * @access protected
51
     *
52
     * @return void
53
     */
54
    protected function addPlayerJS()
55
    {
56
        // Inline CSS.
57
        $inlineCSS = '#tx-dlf-audio { width: 100px; height: 100px; }';
58
59
        // AudioPlayer configuration.
60
        $audioPlayerConfiguration = '
61
            $(document).ready(function() {
62
                AudioPlayer = new dlfAudioPlayer({
63
                    audio: {
64
                        mimeType: "' . $this->audio['mimetype'] . '",
65
                        title: "' . $this->audio['label'] . '",
66
                        url:  "' . $this->audio['url'] . '"
67
                    },
68
                    parentElId: "tx-dlf-audio",
69
                    swfPath: "' . PathUtility::stripPathSitePrefix(ExtensionManagementUtility::extPath($this->extKey)) . 'Resources/Public/Javascript/jPlayer/jquery.jplayer.swf"
70
                });
71
            });
72
        ';
73
74
        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
75
        $pageRenderer->addCssInlineBlock('kitodo-audioplayer-configuration', $inlineCSS);
76
        $pageRenderer->addJsFooterInlineCode('kitodo-audioplayer-configuration', $audioPlayerConfiguration);
77
    }
78
79
    /**
80
     * The main method of the PlugIn
81
     *
82
     * @access public
83
     */
84
    public function mainAction()
85
    {
86
        $requestData = GeneralUtility::_GPmerged('tx_dlf');
87
        unset($requestData['__referrer'], $requestData['__trustedProperties']);
88
89
        // Load current document.
90
        $this->loadDocument($requestData);
91
        if (
92
            $this->doc === null
93
            || $this->doc->numPages < 1
94
        ) {
95
            // Quit without doing anything if required variables are not set.
96
            return;
97
        } else {
98
            // Set default values if not set.
99
            // $requestData['page'] may be integer or string (physical structure @ID)
100
            if (
101
                (int) $requestData['page'] > 0
102
                || empty($requestData['page'])
103
            ) {
104
                $requestData['page'] = MathUtility::forceIntegerInRange((int) $requestData['page'], 1, $this->doc->numPages, 1);
105
            } else {
106
                $requestData['page'] = array_search($requestData['page'], $this->doc->physicalStructure);
107
            }
108
            $requestData['double'] = MathUtility::forceIntegerInRange($requestData['double'], 0, 1, 0);
109
        }
110
        // Check if there are any audio files available.
111
        $fileGrpsAudio = GeneralUtility::trimExplode(',', $this->settings['fileGrpAudio']);
112
        while ($fileGrpAudio = array_shift($fileGrpsAudio)) {
113
            if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpAudio])) {
114
                // Get audio data.
115
                $this->audio['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpAudio]);
116
                $this->audio['label'] = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['label'];
117
                $this->audio['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$requestData['page']]]['files'][$fileGrpAudio]);
118
                break;
119
            }
120
        }
121
        if (!empty($this->audio)) {
122
            // Add jPlayer javascript.
123
            $this->addPlayerJS();
124
        } else {
125
            // Quit without doing anything if required variables are not set.
126
            return;
127
        }
128
    }
129
130
    // TODO: Needs to be placed in an abstract class
131
    /**
132
     * Loads the current document into $this->doc
133
     *
134
     * @access protected
135
     *
136
     * @return void
137
     */
138
    protected function loadDocument($requestData)
139
    {
140
        // Check for required variable.
141
        if (
142
            !empty($requestData['id'])
143
            && !empty($this->settings['pages'])
144
        ) {
145
            // Should we exclude documents from other pages than $this->settings['pages']?
146
            $pid = (!empty($this->settings['excludeOther']) ? intval($this->settings['pages']) : 0);
147
            // Get instance of \Kitodo\Dlf\Common\Document.
148
            $this->doc = Document::getInstance($requestData['id'], $pid);
0 ignored issues
show
Bug Best Practice introduced by
The property doc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
149
            if (!$this->doc->ready) {
150
                // Destroy the incomplete object.
151
                $this->doc = null;
152
                $this->logger->error('Failed to load document with UID ' . $requestData['id']);
153
            } else {
154
                // Set configuration PID.
155
                $this->doc->cPid = $this->settings['pages'];
156
            }
157
        } elseif (!empty($requestData['recordId'])) {
158
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Controller\ConnectionPool was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
159
                ->getQueryBuilderForTable('tx_dlf_documents');
160
161
            // Get UID of document with given record identifier.
162
            $result = $queryBuilder
163
                ->select('tx_dlf_documents.uid AS uid')
164
                ->from('tx_dlf_documents')
165
                ->where(
166
                    $queryBuilder->expr()->eq('tx_dlf_documents.record_id', $queryBuilder->expr()->literal($requestData['recordId'])),
167
                    Helper::whereExpression('tx_dlf_documents')
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Controller\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
168
                )
169
                ->setMaxResults(1)
170
                ->execute();
171
172
            if ($resArray = $result->fetch()) {
173
                $requestData['id'] = $resArray['uid'];
174
                // Set superglobal $_GET array and unset variables to avoid infinite looping.
175
                $_GET[$this->prefixId]['id'] = $requestData['id'];
176
                unset($requestData['recordId'], $_GET[$this->prefixId]['recordId']);
177
                // Try to load document.
178
                $this->loadDocument($requestData);
179
            } else {
180
                $this->logger->error('Failed to load document with record ID "' . $requestData['recordId'] . '"');
181
            }
182
        } else {
183
            $this->logger->error('Invalid UID ' . $requestData['id'] . ' or PID ' . $this->settings['pages'] . ' for document loading');
184
        }
185
    }
186
}
187
188