FileMutexFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Mutex\File;
6
7
use Yiisoft\Mutex\MutexFactory;
8
use Yiisoft\Mutex\MutexInterface;
9
10
/**
11
 * Allows creating file mutex objects.
12
 */
13
final class FileMutexFactory extends MutexFactory
14
{
15
    private string $mutexPath;
16
    private int $directoryMode;
17
    private ?int $fileMode;
18
19
    /**
20
     * @param string $mutexPath The directory to store mutex files.
21
     * @param int $directoryMode The permission to be set for newly created directories.
22
     * This value will be used by PHP {@see chmod()} function. No umask will be applied. Defaults to 0775,
23
     * meaning the directory is read-writable by owner and group, but read-only for other users.
24
     * @param int|null $fileMode The permission to be set for newly created mutex files.
25
     * This value will be used by PHP {@see chmod()} function. No umask will be applied.
26
     */
27 1
    public function __construct(string $mutexPath, int $directoryMode = 0775, int $fileMode = null)
28
    {
29 1
        $this->mutexPath = $mutexPath;
30 1
        $this->directoryMode = $directoryMode;
31 1
        $this->fileMode = $fileMode;
32
    }
33
34 1
    public function create(string $name): MutexInterface
35
    {
36 1
        return new FileMutex($name, $this->mutexPath, $this->directoryMode, $this->fileMode);
37
    }
38
}
39