Passed
Push — master ( e46a83...630973 )
by Alexander
20:03 queued 17:27
created

FileMutexFactory::withDirectoryMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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