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 (#715)
by Alexander
03:39
created

StatisticsController::mainAction()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 155
Code Lines 113

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 113
c 1
b 0
f 0
dl 0
loc 155
rs 7.3777
cc 6
nc 8
nop 0

How to fix   Long Method   

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
namespace Kitodo\Dlf\Controller;
13
14
use Kitodo\Dlf\Common\Helper;
15
use TYPO3\CMS\Core\Database\Connection;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
19
20
/**
21
 * Controller for the plugin 'Statistics' for the 'dlf' extension
22
 *
23
 * @author Sebastian Meyer <[email protected]>
24
 * @package TYPO3
25
 * @subpackage dlf
26
 * @access public
27
 */
28
class StatisticsController extends AbstractController
29
{
30
31
    /**
32
     * The main method of the plugin
33
     *
34
     * @return void
35
     */
36
    public function mainAction()
37
    {
38
        // Quit without doing anything if required configuration variables are not set.
39
        if (empty($this->settings['pages'])) {
40
            $this->logger->warning('Incomplete plugin configuration');
1 ignored issue
show
Bug introduced by
The method warning() does not exist on null. ( Ignorable by Annotation )

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

40
            $this->logger->/** @scrutinizer ignore-call */ 
41
                           warning('Incomplete plugin configuration');

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...
41
        }
42
43
        // Check for selected collections.
44
        if ($this->settings['collections']) {
45
            // Include only selected collections.
46
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
47
                ->getQueryBuilderForTable('tx_dlf_documents');
48
49
            $countTitles = $queryBuilder
50
                ->count('tx_dlf_documents.uid')
51
                ->from('tx_dlf_documents')
52
                ->innerJoin(
53
                    'tx_dlf_documents',
54
                    'tx_dlf_relations',
55
                    'tx_dlf_relations_joins',
56
                    $queryBuilder->expr()->eq(
57
                        'tx_dlf_relations_joins.uid_local',
58
                        'tx_dlf_documents.uid'
59
                    )
60
                )
61
                ->innerJoin(
62
                    'tx_dlf_relations_joins',
63
                    'tx_dlf_collections',
64
                    'tx_dlf_collections_join',
65
                    $queryBuilder->expr()->eq(
66
                        'tx_dlf_relations_joins.uid_foreign',
67
                        'tx_dlf_collections_join.uid'
68
                    )
69
                )
70
                ->where(
71
                    $queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($this->settings['pages'])),
72
                    $queryBuilder->expr()->eq('tx_dlf_collections_join.pid', intval($this->settings['pages'])),
73
                    $queryBuilder->expr()->eq('tx_dlf_documents.partof', 0),
74
                    $queryBuilder->expr()->in('tx_dlf_collections_join.uid',
75
                        $queryBuilder->createNamedParameter(GeneralUtility::intExplode(',',
76
                            $this->settings['collections']), Connection::PARAM_INT_ARRAY)),
77
                    $queryBuilder->expr()->eq('tx_dlf_relations_joins.ident',
78
                        $queryBuilder->createNamedParameter('docs_colls'))
79
                )
80
                ->execute()
81
                ->fetchColumn(0);
82
83
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
84
                ->getQueryBuilderForTable('tx_dlf_documents');
85
            $subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
86
                ->getQueryBuilderForTable('tx_dlf_documents');
87
88
            $subQuery = $subQueryBuilder
89
                ->select('tx_dlf_documents.partof')
90
                ->from('tx_dlf_documents')
91
                ->where(
92
                    $subQueryBuilder->expr()->neq('tx_dlf_documents.partof', 0)
93
                )
94
                ->groupBy('tx_dlf_documents.partof')
95
                ->getSQL();
96
97
            $countVolumes = $queryBuilder
98
                ->count('tx_dlf_documents.uid')
99
                ->from('tx_dlf_documents')
100
                ->innerJoin(
101
                    'tx_dlf_documents',
102
                    'tx_dlf_relations',
103
                    'tx_dlf_relations_joins',
104
                    $queryBuilder->expr()->eq(
105
                        'tx_dlf_relations_joins.uid_local',
106
                        'tx_dlf_documents.uid'
107
                    )
108
                )
109
                ->innerJoin(
110
                    'tx_dlf_relations_joins',
111
                    'tx_dlf_collections',
112
                    'tx_dlf_collections_join',
113
                    $queryBuilder->expr()->eq(
114
                        'tx_dlf_relations_joins.uid_foreign',
115
                        'tx_dlf_collections_join.uid'
116
                    )
117
                )
118
                ->where(
119
                    $queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($this->settings['pages'])),
120
                    $queryBuilder->expr()->eq('tx_dlf_collections_join.pid', intval($this->settings['pages'])),
121
                    $queryBuilder->expr()->notIn('tx_dlf_documents.uid', $subQuery),
122
                    $queryBuilder->expr()->in('tx_dlf_collections_join.uid',
123
                        $queryBuilder->createNamedParameter(GeneralUtility::intExplode(',',
124
                            $this->settings['collections']), Connection::PARAM_INT_ARRAY)),
125
                    $queryBuilder->expr()->eq('tx_dlf_relations_joins.ident',
126
                        $queryBuilder->createNamedParameter('docs_colls'))
127
                )
128
                ->execute()
129
                ->fetchColumn(0);
130
        } else {
131
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
132
                ->getQueryBuilderForTable('tx_dlf_documents');
133
134
            // Include all collections.
135
            $countTitles = $queryBuilder
136
                ->count('tx_dlf_documents.uid')
137
                ->from('tx_dlf_documents')
138
                ->where(
139
                    $queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($this->settings['pages'])),
140
                    $queryBuilder->expr()->eq('tx_dlf_documents.partof', 0),
141
                    Helper::whereExpression('tx_dlf_documents')
142
                )
143
                ->execute()
144
                ->fetchColumn(0);
145
146
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
147
                ->getQueryBuilderForTable('tx_dlf_documents');
148
            $subQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
149
                ->getQueryBuilderForTable('tx_dlf_documents');
150
151
            $subQuery = $subQueryBuilder
152
                ->select('tx_dlf_documents.partof')
153
                ->from('tx_dlf_documents')
154
                ->where(
155
                    $subQueryBuilder->expr()->neq('tx_dlf_documents.partof', 0)
156
                )
157
                ->groupBy('tx_dlf_documents.partof')
158
                ->getSQL();
159
160
            $countVolumes = $queryBuilder
161
                ->count('tx_dlf_documents.uid')
162
                ->from('tx_dlf_documents')
163
                ->where(
164
                    $queryBuilder->expr()->eq('tx_dlf_documents.pid', intval($this->settings['pages'])),
165
                    $queryBuilder->expr()->notIn('tx_dlf_documents.uid', $subQuery)
166
                )
167
                ->execute()
168
                ->fetchColumn(0);
169
        }
170
171
        // Set replacements.
172
        $args['###TITLES###'] = $countTitles . ' ' . htmlspecialchars(
173
            LocalizationUtility::translate(
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...tles' : 'title', 'dlf') can also be of type null; however, parameter $string of htmlspecialchars() does only seem to accept string, 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

173
            /** @scrutinizer ignore-type */ LocalizationUtility::translate(
Loading history...
174
                ($countTitles > 1 ? 'titles' : 'title'), 'dlf'
175
            )
176
        );
177
178
        $args['###VOLUMES###'] = $countVolumes . ' ' . htmlspecialchars(
179
            LocalizationUtility::translate(
180
                ($countTitles > 1 ? 'volumes' : 'volume'), 'dlf'
181
            )
182
        );
183
184
        // Apply replacements.
185
        $content = $this->settings['description'];
186
        foreach ($args as $key => $value) {
187
            $content = str_replace($key, $value, $content);
188
        }
189
190
        $this->view->assign('content', $content);
191
    }
192
}
193