Passed
Pull Request — master (#108)
by Ralf
02:40
created

PreviewViewHelper::render()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 52
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 9
nop 4
dl 0
loc 52
rs 8.6666
c 0
b 0
f 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
namespace EWW\Dpf\ViewHelpers\Link;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\GeneralUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use TYPO3\CMS\Core\Utility\MathUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\MathUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use TYPO3\CMS\Backend\Utility\BackendUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Utility\BackendUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Fluid\ViewHelp...stractBackendViewHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
class PreviewViewHelper extends AbstractBackendViewHelper
23
{
24
25
    /**
26
     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Config...urationManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
     */
28
    protected $configurationManager;
29
30
    /**
31
     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
32
     * @return void
33
     */
34
    public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
35
    {
36
        $this->configurationManager = $configurationManager;
37
    }
38
39
    /**
40
     * documentRepository
41
     *
42
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
43
     * @inject
44
     */
45
    protected $documentRepository;
46
47
    /**
48
     * Returns the View Icon with link
49
     *
50
     * @param array $row Data row
51
     * @param integer $viewPage Detail View page id
52
     * @param  integer $apiPid
53
     * @param  string $insideText
54
     * @param  string $class
55
     * @return string html output
56
     */
57
    protected function getViewIcon(array $row, $pageUid, $apiPid, $insideText, $class)
58
    {
59
60
        $previewMets = BackendUtility::getViewDomain($pageUid)
61
            . '/index.php?id=' . $apiPid
62
            . '&tx_dpf[qid]=' . $row['uid']
63
            . '&tx_dpf[action]=' . $row['action'];
64
65
        if (array_key_exists('deliverInactive', $row)) {
66
            $previewMets .= '&tx_dpf[deliverInactive]=' . $row['deliverInactive'];
67
        }
68
69
        $additionalGetVars = '&tx_dlf[id]=' . urlencode($previewMets) . '&no_cache=1';
70
        $title = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('manager.tooltip.preview', 'dpf', $arguments = null);
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Utility\LocalizationUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
71
        $icon = '<a href="#" data-toggle="tooltip" class="' . $class . '" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($pageUid, $this->backPath, '', '', '', $additionalGetVars)) . '" title="' . $title . '">' .
72
                          $insideText . '</a>';
73
74
        return $icon;
75
76
    }
77
78
    /**
79
     * Renders a record list as known from the TYPO3 list module
80
     * Note: This feature is experimental!
81
     *
82
     * @param array() $arguments
83
     * @param  integer $pageUid
84
     * @param  integer $apiPid
85
     * @param  string $class
86
     * @return string the rendered record list
87
     */
88
    public function render(array $arguments, $pageUid, $apiPid, $class)
89
    {
90
91
        if ($arguments['document']) {
92
93
            // it's already a document object?
94
            if ($arguments['document'] instanceof \EWW\Dpf\Domain\Model\Document) {
95
96
                $document = $arguments['document'];
97
98
            } else if (MathUtility::canBeInterpretedAsInteger($arguments['document'])) {
99
100
                $document = $this->documentRepository->findByUid($arguments['document']);
101
102
            }
103
104
            // we found a valid document
105
            if ($document) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $document does not seem to be defined for all execution paths leading up to this point.
Loading history...
106
107
                $row['uid'] = $document->getUid();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$row was never initialized. Although not strictly required by PHP, it is generally a good practice to add $row = array(); before regardless.
Loading history...
108
109
                $row['title'] = $document->getTitle();
110
111
                $row['action'] = 'preview';
112
113
            } else {
114
115
                // ok, nothing to render. So return empty content.
116
                return '';
117
118
            }
119
120
        } else if ($arguments['documentObjectIdentifier']) {
121
122
            $row['action'] = 'mets';
123
124
            $row['uid'] = $arguments['documentObjectIdentifier'];
125
126
            // pass configured API secret key parameter to enable dissemination of inactive documents
127
            $settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $configurationManager seems to be never defined.
Loading history...
Bug introduced by
The type EWW\Dpf\ViewHelpers\Link...urationManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
128
129
            if (array_key_exists('plugin.tx_dpf.settings.deliverInactiveSecretKey', $settings)) {
130
                $row['deliverInactive'] = $this->settings['plugin.tx_dpf.settings.deliverInactiveSecretKey'];
131
            }
132
133
        }
134
135
        $insideText = $this->renderChildren();
136
137
        $content = $this->getViewIcon($row, $pageUid, $apiPid, $insideText, $class);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $row does not seem to be defined for all execution paths leading up to this point.
Loading history...
138
139
        return $content;
140
141
    }
142
}
143