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 ( 14584b...f60880 )
by Sebastian
02:42
created

Feeds::main()   D

Complexity

Conditions 19
Paths 28

Size

Total Lines 126
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 89
nc 28
nop 2
dl 0
loc 126
rs 4.5166
c 0
b 0
f 0

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
namespace Kitodo\Dlf\Plugin;
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\Document;
15
use Kitodo\Dlf\Common\Helper;
16
17
/**
18
 * Plugin 'Feeds' for the 'dlf' extension
19
 *
20
 * @author Sebastian Meyer <[email protected]>
21
 * @package TYPO3
22
 * @subpackage dlf
23
 * @access public
24
 */
25
class Feeds extends \Kitodo\Dlf\Common\AbstractPlugin {
26
    public $scriptRelPath = 'Classes/Plugin/Feeds.php';
27
28
    /**
29
     * The main method of the PlugIn
30
     *
31
     * @access public
32
     *
33
     * @param string $content: The PlugIn content
34
     * @param array $conf: The PlugIn configuration
35
     *
36
     * @return void
37
     */
38
    public function main($content, $conf) {
39
        $this->init($conf);
40
        // Don't cache the output.
41
        $this->setCache(FALSE);
42
        // Create XML document.
43
        $rss = new \DOMDocument('1.0', 'utf-8');
44
        // Add mandatory root element.
45
        $root = $rss->createElement('rss');
46
        $root->setAttribute('version', '2.0');
47
        // Add channel element.
48
        $channel = $rss->createElement('channel');
49
        $channel->appendChild($rss->createElement('title', htmlspecialchars($this->conf['title'], ENT_NOQUOTES, 'UTF-8')));
50
        $channel->appendChild($rss->createElement('link', htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->pi_linkTP_keepPIvars_url()), ENT_NOQUOTES, 'UTF-8')));
51
        if (!empty($this->conf['description'])) {
52
            $channel->appendChild($rss->createElement('description', htmlspecialchars($this->conf['description'], ENT_QUOTES, 'UTF-8')));
53
        }
54
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
55
            'tx_dlf_libraries.label AS label',
56
            'tx_dlf_libraries',
57
            'tx_dlf_libraries.pid='.intval($this->conf['pages'])
58
                .' AND tx_dlf_libraries.uid='.intval($this->conf['library'])
59
                .Helper::whereClause('tx_dlf_libraries'),
60
            '',
61
            '',
62
            '1'
63
        );
64
        if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
65
            $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
66
            $channel->appendChild($rss->createElement('copyright', htmlspecialchars($resArray['label'], ENT_NOQUOTES, 'UTF-8')));
67
        }
68
        $channel->appendChild($rss->createElement('pubDate', date('r', $GLOBALS['EXEC_TIME'])));
69
        $channel->appendChild($rss->createElement('generator', htmlspecialchars($this->conf['useragent'], ENT_NOQUOTES, 'UTF-8')));
70
        // Add item elements.
71
        if (!$this->conf['excludeOther']
72
            || empty($this->piVars['collection'])
73
            || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->conf['collections'], $this->piVars['collection'])) {
74
            $additionalWhere = '';
75
            // Check for pre-selected collections.
76
            if (!empty($this->piVars['collection'])) {
77
                $additionalWhere = ' AND tx_dlf_collections.uid='.intval($this->piVars['collection']);
78
            } elseif (!empty($this->conf['collections'])) {
79
                $additionalWhere = ' AND tx_dlf_collections.uid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->conf['collections']).')';
80
            }
81
            $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
82
                'tx_dlf_documents.uid AS uid,tx_dlf_documents.partof AS partof,tx_dlf_documents.title AS title,tx_dlf_documents.volume AS volume,tx_dlf_documents.author AS author,tx_dlf_documents.record_id AS guid,tx_dlf_documents.tstamp AS tstamp,tx_dlf_documents.crdate AS crdate',
83
                'tx_dlf_documents',
84
                'tx_dlf_relations',
85
                'tx_dlf_collections',
86
                'AND tx_dlf_documents.pid='.intval($this->conf['pages'])
87
                    .' AND tx_dlf_relations.ident='.$GLOBALS['TYPO3_DB']->fullQuoteStr('docs_colls', 'tx_dlf_relations')
88
                    .' AND tx_dlf_collections.pid='.intval($this->conf['pages'])
89
                    .$additionalWhere
90
                    .Helper::whereClause('tx_dlf_documents')
91
                    .Helper::whereClause('tx_dlf_collections'),
92
                'tx_dlf_documents.uid',
93
                'tx_dlf_documents.tstamp DESC',
94
                intval($this->conf['limit'])
95
            );
96
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
97
                // Add each record as item element.
98
                while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
99
                    $item = $rss->createElement('item');
100
                    $title = '';
101
                    // Get title of superior document.
102
                    if ((empty($resArray['title']) || !empty($this->conf['prependSuperiorTitle']))
103
                        && !empty($resArray['partof'])) {
104
                        $superiorTitle = Document::getTitle($resArray['partof'], TRUE);
105
                        if (!empty($superiorTitle)) {
106
                            $title .= '['.$superiorTitle.']';
107
                        }
108
                    }
109
                    // Get title of document.
110
                    if (!empty($resArray['title'])) {
111
                        $title .= ' '.$resArray['title'];
112
                    }
113
                    // Set default title if empty.
114
                    if (empty($title)) {
115
                        $title = $this->pi_getLL('noTitle');
116
                    }
117
                    // Append volume information.
118
                    if (!empty($resArray['volume'])) {
119
                        $title .= ', '.$this->pi_getLL('volume').' '.$resArray['volume'];
120
                    }
121
                    // Is this document new or updated?
122
                    if ($resArray['crdate'] == $resArray['tstamp']) {
123
                        $title = $this->pi_getLL('new').' '.trim($title);
124
                    } else {
125
                        $title = $this->pi_getLL('update').' '.trim($title);
126
                    }
127
                    $item->appendChild($rss->createElement('title', htmlspecialchars($title, ENT_NOQUOTES, 'UTF-8')));
128
                    // Add link.
129
                    $linkConf = [
130
                        'parameter' => $this->conf['targetPid'],
131
                        'forceAbsoluteUrl' => 1,
132
                        'additionalParams' => \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, ['id' => $resArray['uid']], '', TRUE, FALSE)
133
                    ];
134
                    $item->appendChild($rss->createElement('link', htmlspecialchars($this->cObj->typoLink_URL($linkConf), ENT_NOQUOTES, 'UTF-8')));
135
                    // Add author if applicable.
136
                    if (!empty($resArray['author'])) {
137
                        $item->appendChild($rss->createElement('author', htmlspecialchars($resArray['author'], ENT_NOQUOTES, 'UTF-8')));
138
                    }
139
                    // Add online publication date.
140
                    $item->appendChild($rss->createElement('pubDate', date('r', $resArray['crdate'])));
141
                    // Add internal record identifier.
142
                    $item->appendChild($rss->createElement('guid', htmlspecialchars($resArray['guid'], ENT_NOQUOTES, 'UTF-8')));
143
                    $channel->appendChild($item);
144
                }
145
            }
146
        }
147
        $root->appendChild($channel);
148
        // Build XML output.
149
        $rss->appendChild($root);
150
        $content = $rss->saveXML();
151
        // Clean output buffer.
152
        \TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers();
0 ignored issues
show
Bug introduced by
The method cleanOutputBuffers() does not exist on TYPO3\CMS\Core\Utility\GeneralUtility. ( Ignorable by Annotation )

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

152
        \TYPO3\CMS\Core\Utility\GeneralUtility::/** @scrutinizer ignore-call */ 
153
                                                cleanOutputBuffers();

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...
153
        // Send headers.
154
        header('HTTP/1.1 200 OK');
155
        header('Cache-Control: no-cache');
156
        header('Content-Length: '.strlen($content));
157
        header('Content-Type: application/rss+xml; charset=utf-8');
158
        header('Date: '.date('r', $GLOBALS['EXEC_TIME']));
159
        header('Expires: '.date('r', $GLOBALS['EXEC_TIME']));
160
        echo $content;
161
        // Flush output buffer and end script processing.
162
        ob_end_flush();
163
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
164
    }
165
}
166