Volume   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A want() 0 6 2
A has() 0 3 1
A remove() 0 6 3
A __construct() 0 4 1
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