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 — master ( 8b5010...f1d707 )
by Sebastian
02:41
created

AbstractPlugin   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 209
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 22
eloc 75
dl 0
loc 209
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplate() 0 7 2
A init() 0 32 6
A parseTS() 0 4 1
A pi_wrapInBaseClass() 0 9 3
A setCache() 0 15 3
B loadDocument() 0 39 7
1
<?php
2
namespace Kitodo\Dlf\Common;
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
/**
15
 * Abstract plugin class for the 'dlf' extension
16
 *
17
 * @author Sebastian Meyer <[email protected]>
18
 * @package TYPO3
19
 * @subpackage dlf
20
 * @access public
21
 * @abstract
22
 */
23
abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
24
    public $extKey = 'dlf';
25
    public $prefixId = 'tx_dlf';
26
    public $scriptRelPath = 'Classes/Common/AbstractPlugin.php';
27
    // Plugins are cached by default (@see setCache()).
28
    public $pi_USER_INT_obj = FALSE;
29
    public $pi_checkCHash = TRUE;
30
31
    /**
32
     * This holds the current document
33
     *
34
     * @var \Kitodo\Dlf\Common\Document
35
     * @access protected
36
     */
37
    protected $doc;
38
39
    /**
40
     * This holds the plugin's parsed template
41
     *
42
     * @var string
43
     * @access protected
44
     */
45
    protected $template = '';
46
47
    /**
48
     * Read and parse the template file
49
     *
50
     * @access protected
51
     *
52
     * @param string $part: Name of the subpart to load
53
     *
54
     * @return void
55
     */
56
    protected function getTemplate($part = '###TEMPLATE###') {
57
        if (!empty($this->conf['templateFile'])) {
58
            // Load template file from configuration.
59
            $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), $part);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Frontend\Conte...enderer::fileResource() has been deprecated: since TYPO3 v8, will be removed in TYPO3 v9, use file_get_contents() directly ( Ignorable by Annotation )

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

59
            $this->template = $this->cObj->getSubpart(/** @scrutinizer ignore-deprecated */ $this->cObj->fileResource($this->conf['templateFile']), $part);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function TYPO3\CMS\Frontend\Conte...tRenderer::getSubpart() has been deprecated: since TYPO3 v8, will be removed in TYPO3 v9, please use the MarkerBasedTemplateService instead. ( Ignorable by Annotation )

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

59
            $this->template = /** @scrutinizer ignore-deprecated */ $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), $part);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
60
        } else {
61
            // Load default template file.
62
            $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/Resources/Private/Templates/'.Helper::getUnqualifiedClassName(get_class($this)).'.tmpl'), $part);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Frontend\Conte...enderer::fileResource() has been deprecated: since TYPO3 v8, will be removed in TYPO3 v9, use file_get_contents() directly ( Ignorable by Annotation )

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

62
            $this->template = $this->cObj->getSubpart(/** @scrutinizer ignore-deprecated */ $this->cObj->fileResource('EXT:dlf/Resources/Private/Templates/'.Helper::getUnqualifiedClassName(get_class($this)).'.tmpl'), $part);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function TYPO3\CMS\Frontend\Conte...tRenderer::getSubpart() has been deprecated: since TYPO3 v8, will be removed in TYPO3 v9, please use the MarkerBasedTemplateService instead. ( Ignorable by Annotation )

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

62
            $this->template = /** @scrutinizer ignore-deprecated */ $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/Resources/Private/Templates/'.Helper::getUnqualifiedClassName(get_class($this)).'.tmpl'), $part);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
63
        }
64
    }
65
66
    /**
67
     * All the needed configuration values are stored in class variables
68
     * Priority: Flexforms > TS-Templates > Extension Configuration > ext_localconf.php
69
     *
70
     * @access protected
71
     *
72
     * @param array $conf: configuration array from TS-Template
73
     *
74
     * @return void
75
     */
76
    protected function init(array $conf) {
77
        // Read FlexForm configuration.
78
        $flexFormConf = [];
79
        $this->cObj->readFlexformIntoConf($this->cObj->data['pi_flexform'], $flexFormConf);
80
        if (!empty($flexFormConf)) {
81
            $conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($flexFormConf, $conf);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $conf is correct as TYPO3\CMS\Core\Utility\A...e($flexFormConf, $conf) targeting TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
82
        }
83
        // Read plugin TS configuration.
84
        $pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_'.strtolower(Helper::getUnqualifiedClassName(get_class($this))).'.'];
85
        if (is_array($pluginConf)) {
86
            $conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConf, $conf);
0 ignored issues
show
Bug introduced by
It seems like $conf can also be of type null; however, parameter $overrule of TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

86
            $conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConf, /** @scrutinizer ignore-type */ $conf);
Loading history...
Bug introduced by
Are you sure the assignment to $conf is correct as TYPO3\CMS\Core\Utility\A...ule($pluginConf, $conf) targeting TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
87
        }
88
        // Read general TS configuration.
89
        $generalConf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId.'.'];
90
        if (is_array($generalConf)) {
91
            $conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($generalConf, $conf);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $conf is correct as TYPO3\CMS\Core\Utility\A...le($generalConf, $conf) targeting TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
92
        }
93
        // Read extension configuration.
94
        $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]);
95
        if (is_array($extConf)) {
96
            $conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($extConf, $conf);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $conf is correct as TYPO3\CMS\Core\Utility\A...errule($extConf, $conf) targeting TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
97
        }
98
        // Read TYPO3_CONF_VARS configuration.
99
        $varsConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey];
100
        if (is_array($varsConf)) {
101
            $conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($varsConf, $conf);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $conf is correct as TYPO3\CMS\Core\Utility\A...rrule($varsConf, $conf) targeting TYPO3\CMS\Core\Utility\A...RecursiveWithOverrule() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
102
        }
103
        $this->conf = $conf;
104
        // Set default plugin variables.
105
        $this->pi_setPiVarDefaults();
106
        // Load translation files.
107
        $this->pi_loadLL('EXT:'.$this->extKey.'/Resources/Private/Language/'.Helper::getUnqualifiedClassName(get_class($this)).'.xml');
108
    }
109
110
    /**
111
     * Loads the current document into $this->doc
112
     *
113
     * @access protected
114
     *
115
     * @return void
116
     */
117
    protected function loadDocument() {
118
        // Check for required variable.
119
        if (!empty($this->piVars['id'])
120
            && !empty($this->conf['pages'])) {
121
            // Should we exclude documents from other pages than $this->conf['pages']?
122
            $pid = (!empty($this->conf['excludeOther']) ? intval($this->conf['pages']) : 0);
123
            // Get instance of \Kitodo\Dlf\Common\Document.
124
            $this->doc = Document::getInstance($this->piVars['id'], $pid);
125
            if (!$this->doc->ready) {
0 ignored issues
show
Bug Best Practice introduced by
The property $ready is declared protected in Kitodo\Dlf\Common\Document. Since you implement __get, consider adding a @property or @property-read.
Loading history...
126
                // Destroy the incomplete object.
127
                $this->doc = NULL;
128
                Helper::devLog('Failed to load document with UID '.$this->piVars['id'], DEVLOG_SEVERITY_ERROR);
129
            } else {
130
                // Set configuration PID.
131
                $this->doc->cPid = $this->conf['pages'];
0 ignored issues
show
Bug Best Practice introduced by
The property $cPid is declared protected in Kitodo\Dlf\Common\Document. Since you implement __set, consider adding a @property or @property-write.
Loading history...
132
            }
133
        } elseif (!empty($this->piVars['recordId'])) {
134
            // Get UID of document with given record identifier.
135
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
136
                'tx_dlf_documents.uid',
137
                'tx_dlf_documents',
138
                'tx_dlf_documents.record_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['recordId'], 'tx_dlf_documents')
139
                    .Helper::whereClause('tx_dlf_documents'),
140
                '',
141
                '',
142
                '1'
143
            );
144
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1) {
145
                list ($this->piVars['id']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
146
                // Set superglobal $_GET array and unset variables to avoid infinite looping.
147
                $_GET[$this->prefixId]['id'] = $this->piVars['id'];
148
                unset ($this->piVars['recordId'], $_GET[$this->prefixId]['recordId']);
149
                // Try to load document.
150
                $this->loadDocument();
151
            } else {
152
                Helper::devLog('Failed to load document with record ID "'.$this->piVars['recordId'].'"', DEVLOG_SEVERITY_ERROR);
153
            }
154
        } else {
155
            Helper::devLog('Invalid UID '.$this->piVars['id'].' or PID '.$this->conf['pages'].' for document loading', DEVLOG_SEVERITY_ERROR);
156
        }
157
    }
158
159
    /**
160
     * The main method of the PlugIn
161
     *
162
     * @access public
163
     *
164
     * @param string $content: The PlugIn content
165
     * @param array $conf: The PlugIn configuration
166
     *
167
     * @abstract
168
     *
169
     * @return string The content that is displayed on the website
170
     */
171
    abstract public function main($content, $conf);
172
173
    /**
174
     * Wraps the input string in a tag with the class attribute set to the class name
175
     *
176
     * @access public
177
     *
178
     * @param string $content: HTML content to wrap in the div-tags with the class of the plugin
179
     *
180
     * @return string HTML content wrapped, ready to return to the parent object.
181
     */
182
    public function pi_wrapInBaseClass($content) {
183
        if (!$GLOBALS['TSFE']->config['config']['disableWrapInBaseClass']) {
184
            // Use class name instead of $this->prefixId for content wrapping because $this->prefixId is the same for all plugins.
185
            $content = '<div class="tx-dlf-'.Helper::getUnqualifiedClassName(get_class($this)).'">'.$content.'</div>';
186
            if (!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
187
                $content = "\n\n<!-- BEGIN: Content of extension '".$this->extKey."', plugin '".Helper::getUnqualifiedClassName(get_class($this))."' -->\n\n".$content."\n\n<!-- END: Content of extension '".$this->extKey."', plugin '".Helper::getUnqualifiedClassName(get_class($this))."' -->\n\n";
188
            }
189
        }
190
        return $content;
191
    }
192
193
    /**
194
     * Parses a string into a Typoscript array
195
     *
196
     * @access protected
197
     *
198
     * @param string $string: The string to parse
199
     *
200
     * @return array The resulting typoscript array
201
     */
202
    protected function parseTS($string = '') {
203
        $parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
204
        $parser->parse($string);
205
        return $parser->setup;
206
    }
207
208
    /**
209
     * Sets some configuration variables if the plugin is cached.
210
     *
211
     * @access protected
212
     *
213
     * @param boolean $cache: Should the plugin be cached?
214
     *
215
     * @return void
216
     */
217
    protected function setCache($cache = TRUE) {
218
        if ($cache) {
219
            // Set cObject type to "USER" (default).
220
            $this->pi_USER_INT_obj = FALSE;
221
            $this->pi_checkCHash = TRUE;
222
            if (count($this->piVars)) {
223
                // Check cHash or disable caching.
224
                $GLOBALS['TSFE']->reqCHash();
225
            }
226
        } else {
227
            // Set cObject type to "USER_INT".
228
            $this->pi_USER_INT_obj = TRUE;
229
            $this->pi_checkCHash = FALSE;
230
            // Plugins are of type "USER" by default, so convert it to "USER_INT".
231
            $this->cObj->convertToUserIntObject();
232
        }
233
    }
234
}
235