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

SearchInDocumentTool::addSearchInDocumentJS()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace Kitodo\Dlf\Plugin\Tools;
3
4
/**
5
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
6
 *
7
 * This file is part of the Kitodo and TYPO3 projects.
8
 *
9
 * @license GNU General Public License version 3 or later.
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 */
13
14
use Kitodo\Dlf\Common\Helper;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
17
/**
18
 * SearchInDocument tool for the plugin 'Toolbox' of the 'dlf' extension
19
 *
20
 * @author Sebastian Meyer <[email protected]>
21
 * @author Alexander Bigga <[email protected]>
22
 * @package TYPO3
23
 * @subpackage dlf
24
 * @access public
25
 */
26
class SearchInDocumentTool extends \Kitodo\Dlf\Common\AbstractPlugin {
27
    public $scriptRelPath = 'Classes/Plugin/Tools/SearchInDocumentTool.php';
28
29
    /**
30
     * The main method of the PlugIn
31
     *
32
     * @access public
33
     *
34
     * @param string $content: The PlugIn content
35
     * @param array $conf: The PlugIn configuration
36
     *
37
     * @return string The content that is displayed on the website
38
     */
39
    public function main($content, $conf) {
40
41
        $this->init($conf);
42
43
        // Merge configuration with conf array of toolbox.
44
        if (!empty($this->cObj->data['conf'])) {
45
            $this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
46
        }
47
48
        $this->addSearchInDocumentJS();
49
50
        // Load current document.
51
        $this->loadDocument();
52
        if ($this->doc === NULL
53
            || $this->doc->numPages < 1
0 ignored issues
show
Bug Best Practice introduced by
The property $numPages is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
54
            || empty($this->conf['fileGrpFulltext'])
55
            || empty($this->conf['solrcore'])) {
56
            // Quit without doing anything if required variables are not set.
57
            return $content;
58
        }
59
60
        // Quit if no fulltext file is present
61
        $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 Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
Bug Best Practice introduced by
The property $physicalStructure is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
62
        if (empty($fullTextFile)) {
63
            return $content;
64
        }
65
66
        // Load template file.
67
        $this->getTemplate('###TEMPLATE###', '', TRUE);
0 ignored issues
show
Unused Code introduced by
The call to Kitodo\Dlf\Common\AbstractPlugin::getTemplate() has too many arguments starting with TRUE. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        $this->/** @scrutinizer ignore-call */ 
68
               getTemplate('###TEMPLATE###', '', TRUE);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
68
69
        // Configure @action URL for form.
70
        $linkConf = array(
71
            'parameter' => $GLOBALS['TSFE']->id,
72
            'forceAbsoluteUrl' => 1
73
        );
74
75
        $encryptedSolr = $this->getEncryptedCoreName();
76
        // Fill markers.
77
        $markerArray = array(
78
            '###ACTION_URL###' => $this->cObj->typoLink_URL($linkConf),
79
            '###LABEL_QUERY###' => $this->pi_getLL('label.query'),
80
            '###LABEL_DELETE_SEARCH###' => $this->pi_getLL('label.delete_search'),
81
            '###LABEL_LOADING###' => $this->pi_getLL('label.loading'),
82
            '###LABEL_SUBMIT###' => $this->pi_getLL('label.submit'),
83
            '###LABEL_SEARCH_IN_DOCUMENT###' => $this->pi_getLL('label.searchInDocument'),
84
            '###LABEL_NEXT###' => $this->pi_getLL('label.next'),
85
            '###LABEL_PREVIOUS###' => $this->pi_getLL('label.previous'),
86
            '###LABEL_PAGE###' => $this->pi_getLL('label.logicalPage'),
87
            '###CURRENT_DOCUMENT###' => $this->doc->uid,
0 ignored issues
show
Bug Best Practice introduced by
The property $uid is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
88
            '###SOLR_ENCRYPTED###' => isset($encryptedSolr['encrypted']) ? $encryptedSolr['encrypted'] : '',
89
            '###SOLR_HASH###' => isset($encryptedSolr['hash']) ? $encryptedSolr['hash'] : '',
90
        );
91
92
        $content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
93
        return $this->pi_wrapInBaseClass($content);
94
    }
95
96
    /**
97
     * Adds the JS files necessary for search in document
98
     *
99
     * @access protected
100
     *
101
     * @return void
102
     */
103
    protected function addSearchInDocumentJS() {
104
        $pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
105
        $pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'Resources/Public/Javascript/Search/SearchInDocument.js');
106
    }
107
108
    /**
109
     * Get the encrypted Solr core name
110
     *
111
     * @access protected
112
     *
113
     * @return array with encrypted core name and hash
114
     */
115
    protected function getEncryptedCoreName() {
116
        // Get core name.
117
        $name = Helper::getIndexNameFromUid($this->conf['solrcore'], 'tx_dlf_solrcores');
118
        // Encrypt core name.
119
        if (!empty($name)) {
120
            $name = Helper::encrypt($name);
121
        }
122
        return $name;
123
    }
124
}
125