Test Failed
Push — 6-0 ( cfb4d5 )
by Tomas Norre
03:23
created

getActiveProcessCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/***************************************************************
4
 *  Copyright notice
5
 *
6
 *  (c) 2017 AOE GmbH <[email protected]>
7
 *
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
/**
28
 * Class tx_crawler_view_process_list
29
 */
30
class tx_crawler_view_process_list
31
{
32
33
    /**
34
     * @var string template path
35
     */
36
    protected $template = 'EXT:crawler/template/process/list.php';
37
38
    /**
39
     * @var string icon path
40
     */
41
    protected $iconPath;
42
43
    /**
44
     * @var string Holds the path to start a cli process via command line
45
     */
46
    protected $cliPath;
47
48
    /**
49
     * @var int Holds the total number of items pending in the queue to be processed
50
     */
51
    protected $totalItemCount;
52
53
    /**
54
     * @var boolean Holds the enable state of the crawler
55
     */
56
    protected $isCrawlerEnabled;
57
58
    /**
59
     * @var int Holds the number of active processes
60
     */
61
    protected $activeProcessCount;
62
63
    /**
64
     * @var int Holds the number of maximum active processes
65
     */
66
    protected $maxActiveProcessCount;
67
68
    /**
69
     * @var string Holds the mode state, can be simple or detail
70
     */
71
    protected $mode;
72
73
    /**
74
     * @var int Holds the current page id
75
     */
76
    protected $pageId;
77
78
    /**
79
     * @var int $totalItemCount number of total item
80
     */
81
    protected $totalUnprocessedItemCount;
82
83
    /**
84
     * @var int Holds the number of assigned unprocessed items
85
     */
86
    protected $assignedUnprocessedItemCount;
87
88
    /**
89
     * @return int
90
     */
91
    public function getAssignedUnprocessedItemCount()
92
    {
93
        return $this->assignedUnprocessedItemCount;
94
    }
95
96
    /**
97
     * @return int
98
     */
99
    public function getTotalUnprocessedItemCount()
100
    {
101
        return $this->totalUnprocessedItemCount;
102
    }
103
104
    /**
105
     * @param int $assignedUnprocessedItemCount
106
     */
107
    public function setAssignedUnprocessedItemCount($assignedUnprocessedItemCount)
108
    {
109
        $this->assignedUnprocessedItemCount = $assignedUnprocessedItemCount;
110
    }
111
112
    /**
113
     * @param int $totalUnprocessedItemCount
114
     */
115
    public function setTotalUnprocessedItemCount($totalUnprocessedItemCount)
116
    {
117
        $this->totalUnprocessedItemCount = $totalUnprocessedItemCount;
118
    }
119
120
    /**
121
     * Set the page id
122
     *
123
     * @param int $pageId page id
124
     */
125
    public function setPageId($pageId)
126
    {
127
        $this->pageId = $pageId;
128
    }
129
130
    /**
131
     * Get the page id
132
     *
133
     * @return int page id
134
     */
135
    public function getPageId()
136
    {
137
        return $this->pageId;
138
    }
139
140
    /**
141
     * @return string
142
     */
143
    public function getMode()
144
    {
145
        return $this->mode;
146
    }
147
148
    /**
149
     * @param string $mode
150
     */
151
    public function setMode($mode)
152
    {
153
        $this->mode = $mode;
154
    }
155
156
    /**
157
     * @return int
158
     */
159
    public function getMaxActiveProcessCount()
160
    {
161
        return $this->maxActiveProcessCount;
162
    }
163
164
    /**
165
     * @param int $maxActiveProcessCount
166
     */
167
    public function setMaxActiveProcessCount($maxActiveProcessCount)
168
    {
169
        $this->maxActiveProcessCount = $maxActiveProcessCount;
170
    }
171
172
    /**
173
     * @return int
174
     */
175
    public function getActiveProcessCount()
176
    {
177
        return $this->activeProcessCount;
178
    }
179
180
    /**
181
     * @param int $activeProcessCount
182
     */
183
    public function setActiveProcessCount($activeProcessCount)
184
    {
185
        $this->activeProcessCount = $activeProcessCount;
186
    }
187
188
    /**
189
     * @return boolean
190
     */
191
    public function getIsCrawlerEnabled()
192
    {
193
        return $this->isCrawlerEnabled;
194
    }
195
196
    /**
197
     * @param boolean $isCrawlerEnabled
198
     */
199
    public function setIsCrawlerEnabled($isCrawlerEnabled)
200
    {
201
        $this->isCrawlerEnabled = $isCrawlerEnabled;
202
    }
203
204
    /**
205
     * Returns the path to start a cli process from the shell
206
     *
207
     * @return string
208
     */
209
    public function getCliPath()
210
    {
211
        return $this->cliPath;
212
    }
213
214
    /**
215
     * @param string $cliPath
216
     */
217
    public function setCliPath($cliPath)
218
    {
219
        $this->cliPath = $cliPath;
220
    }
221
222
    /**
223
     * @return int
224
     */
225
    public function getTotalItemCount()
226
    {
227
        return $this->totalItemCount;
228
    }
229
230
    /**
231
     * @param int $totalItemCount
232
     */
233
    public function setTotalItemCount($totalItemCount)
234
    {
235
        $this->totalItemCount = $totalItemCount;
236
    }
237
238
    /**
239
     * Method to set the path to the icon from outside
240
     *
241
     * @param string $iconPath
242
     */
243
    public function setIconPath($iconPath)
244
    {
245
        $this->iconPath = $iconPath;
246
    }
247
248
    /**
249
     * Method to read the configured icon path
250
     *
251
     * @return string
252
     */
253
    protected function getIconPath()
254
    {
255
        return $this->iconPath;
256
    }
257
258
    /**
259
     * Method to set a collection of process objects to be displayed in
260
     * the list view.
261
     *
262
     * @param tx_crawler_domain_process_collection $processCollection
263
     */
264
    public function setProcessCollection($processCollection)
265
    {
266
        $this->processCollection = $processCollection;
0 ignored issues
show
Bug Best Practice introduced by
The property processCollection does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
267
    }
268
269
    /**
270
     * Returns a collection of processObjects.
271
     *
272
     * @return tx_crawler_domain_process_collection
273
     */
274
    protected function getProcessCollection()
275
    {
276
        return $this->processCollection;
277
    }
278
279
    /**
280
     * Formats a timestamp as date
281
     *
282
     * @param int $timestamp
283
     *
284
     * @return string
285
     */
286
    protected function asDate($timestamp)
287
    {
288
        if ($timestamp > 0) {
289
            return date($this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:time.detailed'), $timestamp);
0 ignored issues
show
Bug Best Practice introduced by
The expression return date($this->getLL...detailed'), $timestamp) could also return false which is incompatible with the documented return type string. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
290
        } else {
291
            return '';
292
        }
293
    }
294
295
    /**
296
     * Converts seconds into minutes
297
     *
298
     * @param int $seconds
299
     *
300
     * @return float
301
     */
302
    protected function asMinutes($seconds)
303
    {
304
        return round($seconds / 60);
305
    }
306
307
    /**
308
     * Returns a tag for the refresh icon
309
     *
310
     * @return string
311
     */
312
    protected function getRefreshLink()
313
    {
314
        return \AOE\Crawler\Utility\ButtonUtility::getLinkButton(
315
            'actions-refresh',
316
            $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.refresh'),
317
            'window.location=\'' . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_info') . '&SET[crawlaction]=multiprocess&id=' . $this->pageId . '\';'
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...
318
        );
319
    }
320
321
    /**
322
     * Returns a link for the panel to enable or disable the crawler
323
     *
324
     * @return string
325
     */
326
    protected function getEnableDisableLink()
327
    {
328
        if ($this->getIsCrawlerEnabled()) {
329
            // TODO: Icon Should be bigger + Perhaps better icon
330
            return \AOE\Crawler\Utility\ButtonUtility::getLinkButton(
331
                'tx-crawler-stop',
332
                $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.disablecrawling'),
333
                'window.location+=\'&action=stopCrawling\';'
334
            );
335
        } else {
336
            // TODO: Icon Should be bigger
337
            return \AOE\Crawler\Utility\ButtonUtility::getLinkButton(
338
                'tx-crawler-start',
339
                $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.enablecrawling'),
340
                'window.location+=\'&action=resumeCrawling\';'
341
            );
342
        }
343
    }
344
345
    /**
346
     * Get mode link
347
     *
348
     * @param void
349
     *
350
     * @return string a-tag
351
     */
352
    protected function getModeLink()
353
    {
354
        if ($this->getMode() == 'detail') {
355
            return \AOE\Crawler\Utility\ButtonUtility::getLinkButton(
356
                'actions-document-view',
357
                $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.show.running'),
358
                'window.location+=\'&SET[processListMode]=simple\';'
359
            );
360
        } elseif ($this->getMode() == 'simple') {
361
            return \AOE\Crawler\Utility\ButtonUtility::getLinkButton(
362
                'actions-document-view',
363
                $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.show.all'),
364
                'window.location+=\'&SET[processListMode]=detail\';'
365
            );
366
        }
367
    }
368
369
    /**
370
     * Get add link
371
     *
372
     * @param void
373
     *
374
     * @return string a-tag
375
     */
376
    protected function getAddLink()
377
    {
378
        if ($this->getActiveProcessCount() < $this->getMaxActiveProcessCount() && $this->getIsCrawlerEnabled()) {
379
            return \AOE\Crawler\Utility\ButtonUtility::getLinkButton(
380
                'actions-add',
381
                $this->getLLLabel('LLL:EXT:crawler/modfunc1/locallang.xml:labels.process.add'),
382
                'window.location+=\'&action=addProcess\';'
383
            );
384
        } else {
385
            return '';
386
        }
387
    }
388
389
    /**
390
     * Method to render the view.
391
     *
392
     * @return string html content
393
     */
394
    public function render()
395
    {
396
        ob_start();
397
        $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->template);
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...
398
        include($this->template);
399
        $content = ob_get_contents();
400
        ob_end_clean();
401
402
        return $content;
403
    }
404
405
    /**
406
     * retrieve locallanglabel from environment
407
     * just a wrapper should be done in a cleaner way
408
     * later on
409
     *
410
     * @param string $label
411
     *
412
     * @return string
413
     */
414
    protected function getLLLabel($label)
415
    {
416
        return $GLOBALS['LANG']->sL($label);
417
    }
418
}
419