Passed
Push — refactor/backendModule-ValueOb... ( 355cec...0f77d0 )
by Tomas Norre
13:40
created

StartRequestForm::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Backend\RequestForm;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use AOE\Crawler\Utility\MessageUtility;
23
use TYPO3\CMS\Core\Localization\LanguageService;
24
use TYPO3\CMS\Fluid\View\StandaloneView;
25
26
final class StartRequestForm implements RequestForm
27
{
28
    /** @var StandaloneView */
29
    private $view;
30
31
    public function __construct(StandaloneView $view)
32
    {
33
        $this->view = $view;
34
    }
35
36
    public function render($id, string $elementName, array $menuItems): string
37
    {
38
        return $this->showCrawlerInformationAction();
39
    }
40
41
    /*******************************
42
     *
43
     * Generate URLs for crawling:
44
     *
45
     ******************************/
46
47
    /**
48
     * Show a list of URLs to be crawled for each page
49
     */
50
    private function showCrawlerInformationAction(): string
51
    {
52
        $this->view->setTemplate('ShowCrawlerInformation');
53
        if (empty($this->id)) {
54
            $this->isErrorDetected = true;
0 ignored issues
show
Bug Best Practice introduced by
The property isErrorDetected does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
55
            MessageUtility::addErrorMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.noPageSelected'));
56
        } else {
57
            $crawlerParameter = GeneralUtility::_GP('_crawl');
0 ignored issues
show
Bug introduced by
The type AOE\Crawler\Backend\RequestForm\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...
58
            $downloadParameter = GeneralUtility::_GP('_download');
59
60
            $this->duplicateTrack = [];
0 ignored issues
show
Bug Best Practice introduced by
The property duplicateTrack does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
61
            $this->submitCrawlUrls = isset($crawlerParameter);
0 ignored issues
show
Bug Best Practice introduced by
The property submitCrawlUrls does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
62
            $this->downloadCrawlUrls = isset($downloadParameter);
0 ignored issues
show
Bug Best Practice introduced by
The property downloadCrawlUrls does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
63
            $this->makeCrawlerProcessableChecks();
0 ignored issues
show
Bug introduced by
The method makeCrawlerProcessableChecks() does not exist on AOE\Crawler\Backend\RequestForm\StartRequestForm. ( Ignorable by Annotation )

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

63
            $this->/** @scrutinizer ignore-call */ 
64
                   makeCrawlerProcessableChecks();

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...
64
65
            switch ((string) GeneralUtility::_GP('tstamp')) {
66
                case 'midnight':
67
                    $this->scheduledTime = mktime(0, 0, 0);
0 ignored issues
show
Bug Best Practice introduced by
The property scheduledTime does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
68
                    break;
69
                case '04:00':
70
                    $this->scheduledTime = mktime(0, 0, 0) + 4 * 3600;
71
                    break;
72
                case 'now':
73
                default:
74
                    $this->scheduledTime = time();
75
                    break;
76
            }
77
78
            $this->incomingConfigurationSelection = GeneralUtility::_GP('configurationSelection');
0 ignored issues
show
Bug Best Practice introduced by
The property incomingConfigurationSelection does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
79
            $this->incomingConfigurationSelection = is_array($this->incomingConfigurationSelection) ? $this->incomingConfigurationSelection : [];
80
81
            $this->crawlerController = GeneralUtility::makeInstance(CrawlerController::class);
0 ignored issues
show
Bug Best Practice introduced by
The property crawlerController does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The type AOE\Crawler\Backend\RequestForm\CrawlerController 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...
82
            $this->crawlerController->setAccessMode('gui');
83
            $this->crawlerController->setID = GeneralUtility::md5int(microtime());
84
85
            $code = '';
86
            $noConfigurationSelected = empty($this->incomingConfigurationSelection)
87
                || (count($this->incomingConfigurationSelection) === 1 && empty($this->incomingConfigurationSelection[0]));
88
            if ($noConfigurationSelected) {
89
                MessageUtility::addWarningMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.noConfigSelected'));
90
            } else {
91
                if ($this->submitCrawlUrls) {
92
                    $reason = new Reason();
0 ignored issues
show
Bug introduced by
The type AOE\Crawler\Backend\RequestForm\Reason 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...
93
                    $reason->setReason(Reason::REASON_GUI_SUBMIT);
94
                    $reason->setDetailText('The user ' . $GLOBALS['BE_USER']->user['username'] . ' added pages to the crawler queue manually');
95
96
                    $signalPayload = ['reason' => $reason];
97
                    SignalSlotUtility::emitSignal(
0 ignored issues
show
Bug introduced by
The type AOE\Crawler\Backend\RequestForm\SignalSlotUtility 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...
98
                        self::class,
99
                        SignalSlotUtility::SIGNAL_INVOKE_QUEUE_CHANGE,
100
                        $signalPayload
101
                    );
102
                }
103
104
                $code = $this->crawlerController->getPageTreeAndUrls(
105
                    $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on AOE\Crawler\Backend\RequestForm\StartRequestForm. Did you maybe forget to declare it?
Loading history...
106
                    $this->pObj->MOD_SETTINGS['depth'],
0 ignored issues
show
Bug Best Practice introduced by
The property pObj does not exist on AOE\Crawler\Backend\RequestForm\StartRequestForm. Did you maybe forget to declare it?
Loading history...
107
                    $this->scheduledTime,
108
                    $this->reqMinute,
0 ignored issues
show
Bug Best Practice introduced by
The property reqMinute does not exist on AOE\Crawler\Backend\RequestForm\StartRequestForm. Did you maybe forget to declare it?
Loading history...
109
                    $this->submitCrawlUrls,
110
                    $this->downloadCrawlUrls,
111
                    [], // Do not filter any processing instructions
112
                    $this->incomingConfigurationSelection
113
                );
114
            }
115
116
            $this->downloadUrls = $this->crawlerController->downloadUrls;
0 ignored issues
show
Bug Best Practice introduced by
The property downloadUrls does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
117
            $this->duplicateTrack = $this->crawlerController->duplicateTrack;
118
119
            $this->view->assign('noConfigurationSelected', $noConfigurationSelected);
120
            $this->view->assign('submitCrawlUrls', $this->submitCrawlUrls);
121
            $this->view->assign('amountOfUrls', count(array_keys($this->duplicateTrack)));
122
            $this->view->assign('selectors', $this->generateConfigurationSelectors());
0 ignored issues
show
Bug introduced by
The method generateConfigurationSelectors() does not exist on AOE\Crawler\Backend\RequestForm\StartRequestForm. ( Ignorable by Annotation )

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

122
            $this->view->assign('selectors', $this->/** @scrutinizer ignore-call */ generateConfigurationSelectors());

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...
123
            $this->view->assign('code', $code);
124
            $this->view->assign('displayActions', 0);
125
126
            // Download Urls to crawl:
127
            if ($this->downloadCrawlUrls) {
128
                // Creating output header:
129
                header('Content-Type: application/octet-stream');
130
                header('Content-Disposition: attachment; filename=CrawlerUrls.txt');
131
132
                // Printing the content of the CSV lines:
133
                echo implode(chr(13) . chr(10), $this->downloadUrls);
134
                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...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
135
            }
136
        }
137
        return $this->view->render();
138
    }
139
140
    private function getLanguageService(): LanguageService
141
    {
142
        return $GLOBALS['LANG'];
143
    }
144
}
145