Passed
Push — refactor/crawlerController ( 2c0518...acc48a )
by Tomas Norre
07:13
created

Crawler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDisabled() 0 7 3
A __construct() 0 4 2
A isDisabled() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler;
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 TYPO3\CMS\Core\Core\Environment;
23
use TYPO3\CMS\Core\SingletonInterface;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26
final class Crawler implements SingletonInterface
27
{
28
    /**
29
     * @var string
30
     */
31
    private $processFilename;
32
33 37
    public function __construct(string $processFilename = null)
34
    {
35 37
        $this->processFilename = $processFilename ?: Environment::getVarPath() . '/lock/tx_crawler.proc';
36 37
        $this->setDisabled(false);
37 37
    }
38
39 37
    public function setDisabled($disabled = true): void
40
    {
41 37
        if ($disabled) {
42 1
            GeneralUtility::writeFile($this->processFilename, '');
43
        } else {
44 37
            if (is_file($this->processFilename)) {
45 1
                unlink($this->processFilename);
46
            }
47
        }
48 37
    }
49
50 1
    public function isDisabled(): bool
51
    {
52 1
        return is_file($this->processFilename);
53
    }
54
}
55