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

Crawler::setDisabled()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
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