Volume::remove()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
3
namespace kalanis\kw_semaphore\Semaphore;
4
5
6
use kalanis\kw_paths\Stuff;
7
use kalanis\kw_semaphore\Interfaces\ISemaphore;
8
use kalanis\kw_semaphore\Interfaces\ISMTranslations;
9
use kalanis\kw_semaphore\SemaphoreException;
10
use kalanis\kw_semaphore\Traits\TLang;
11
12
13
/**
14
 * Class Volume
15
 * @package kalanis\kw_semaphore\Semaphore
16
 * Data source for semaphore is volume
17
 */
18
class Volume implements ISemaphore
19
{
20
    use TLang;
21
22
    /** @var string path to menu dir */
23
    protected string $rootPath = '';
24
25 5
    public function __construct(string $rootPath, ?ISMTranslations $lang = null)
26
    {
27 5
        $this->rootPath = Stuff::removeEndingSlash($rootPath) . static::EXT_SEMAPHORE;
28 5
        $this->setSmLang($lang);
29 5
    }
30
31 2
    public function want(): bool
32
    {
33 2
        if (false === @file_put_contents($this->rootPath, static::TEXT_SEMAPHORE)) {
34 1
            throw new SemaphoreException($this->getSmLang()->smCannotSaveSemaphore());
35
        }
36 2
        return true;
37
    }
38
39 3
    public function has(): bool
40
    {
41 3
        return is_file($this->rootPath);
42
    }
43
44 2
    public function remove(): bool
45
    {
46 2
        if (file_exists($this->rootPath) && (false === @unlink($this->rootPath))) {
47 1
            throw new SemaphoreException($this->getSmLang()->smCannotOpenSemaphore());
48
        }
49 1
        return true;
50
    }
51
}
52