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
Push — 2.x ( 018833...a970bf )
by Sebastian
08:52 queued 12s
created

tx_dlf_toolsSearchindocument::main()   C

Complexity

Conditions 13
Paths 74

Size

Total Lines 90
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 13
eloc 41
c 3
b 1
f 0
nc 74
nop 2
dl 0
loc 90
rs 6.6166

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
/**
13
 * SearchInDocument tool for the plugin 'Toolbox' of the 'dlf' extension
14
 *
15
 * @author	Alexander Bigga <[email protected]>
16
 * @package	TYPO3
17
 * @subpackage	tx_dlf
18
 * @access	public
19
 */
20
class tx_dlf_toolsSearchindocument extends tx_dlf_plugin {
21
22
    public $scriptRelPath = 'plugins/toolbox/tools/searchindocument/class.tx_dlf_toolsSearchindocument.php';
23
24
    /**
25
     * The main method of the PlugIn
26
     *
27
     * @access	public
28
     *
29
     * @param	string		$content: The PlugIn content
30
     * @param	array		$conf: The PlugIn configuration
31
     *
32
     * @return	string		The content that is displayed on the website
33
     */
34
    public function main($content, $conf) {
35
36
        $this->init($conf);
37
38
        if (!empty($this->cObj->data['conf'])) {
39
            // Merge configuration with conf array of toolbox.
40
            $this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
41
        }
42
43
        $this->addSearchInDocumentJS();
44
45
        // Load current document.
46
        $this->loadDocument();
47
48
        if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpFulltext']) || empty($this->conf['solrcore'])) {
0 ignored issues
show
Bug Best Practice introduced by
The property $numPages is declared protected in tx_dlf_document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
49
50
            // Quit without doing anything if required variables are not set.
51
            return $content;
52
53
        } else {
54
55
            if (!empty($this->piVars['logicalPage'])) {
56
57
                $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
58
                // The logical page parameter should not appear again
59
                unset($this->piVars['logicalPage']);
60
61
            }
62
63
            // Set default values if not set.
64
            // $this->piVars['page'] may be integer or string (physical structure @ID)
65
            if ((int) $this->piVars['page'] > 0 || empty($this->piVars['page'])) {
66
67
                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
68
69
            } else {
70
71
                $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
0 ignored issues
show
Bug Best Practice introduced by
The property $physicalStructure is declared protected in tx_dlf_document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
72
73
            }
74
75
        }
76
77
        // Quit if no fulltext file is present
78
        $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
0 ignored issues
show
Bug Best Practice introduced by
The property $physicalStructureInfo is declared protected in tx_dlf_document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
79
80
        if (empty($fullTextFile)) {
81
82
            return $content;
83
84
        }
85
86
        // Load template file.
87
        if (!empty($this->conf['toolTemplateFile'])) {
88
89
            $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['toolTemplateFile']), '###TEMPLATE###');
90
91
        } else {
92
93
            $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/searchindocument/template.tmpl'), '###TEMPLATE###');
94
95
        }
96
97
        // Configure @action URL for form.
98
        $linkConf = array(
99
            'parameter' => $GLOBALS['TSFE']->id,
100
            'forceAbsoluteUrl' => 1
101
        );
102
103
        $encryptedSolr = $this->getEncryptedCoreName();
104
105
        // Fill markers.
106
        $markerArray = array(
107
            '###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf),
108
            '###LABEL_QUERY###' => $this->pi_getLL('label.query'),
109
            '###LABEL_DELETE_SEARCH###' => $this->pi_getLL('label.delete_search'),
110
            '###LABEL_LOADING###' => $this->pi_getLL('label.loading'),
111
            '###LABEL_SUBMIT###' => $this->pi_getLL('label.submit'),
112
            '###LABEL_SEARCH_IN_DOCUMENT###' => $this->pi_getLL('label.searchInDocument'),
113
            '###LABEL_NEXT###' => $this->pi_getLL('label.next'),
114
            '###LABEL_PREVIOUS###' => $this->pi_getLL('label.previous'),
115
            '###LABEL_PAGE###' => $this->pi_getLL('label.logicalPage'),
116
            '###CURRENT_DOCUMENT###' => $this->doc->uid,
0 ignored issues
show
Bug Best Practice introduced by
The property $uid is declared protected in tx_dlf_document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
117
            '###SOLR_ENCRYPTED###' => isset($encryptedSolr['encrypted']) ? $encryptedSolr['encrypted'] : '',
118
            '###SOLR_HASH###' => isset($encryptedSolr['hash']) ? $encryptedSolr['hash'] : '',
119
        );
120
121
        $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
122
123
        return $this->pi_wrapInBaseClass($content);
124
    }
125
126
    /**
127
     * Adds the JS files necessary for search in document
128
     *
129
     * @access protected
130
     *
131
     * @return void
132
     */
133
    protected function addSearchInDocumentJS() {
134
        $pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
135
        $pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'plugins/toolbox/tools/searchindocument/tx_dlf_search_in_document.js');
136
    }
137
138
    /**
139
     * Get the encrypted Solr core name
140
     *
141
     * @access protected
142
     *
143
     * @return array with encrypted core name and hash
144
     */
145
    protected function getEncryptedCoreName() {
146
        // Get core name.
147
        $name = tx_dlf_helper::getIndexName($this->conf['solrcore'], 'tx_dlf_solrcores');
148
        // Encrypt core name.
149
        if (!empty($name)) {
150
            $name = tx_dlf_helper::encrypt($name);
151
        }
152
        return $name;
153
    }
154
}
155