Passed
Push — master ( 05beb9...f9f1e0 )
by Evgeniy
06:32
created

MutexFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createAndAcquire() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Mutex;
6
7
use RuntimeException;
8
9
/**
10
 * Creates a mutex instance {@see MutexFactoryInterface}.
11
 */
12
abstract class MutexFactory implements MutexFactoryInterface
13
{
14 5
    final public function createAndAcquire(string $name, int $timeout = 0): MutexInterface
15
    {
16 5
        $mutex = $this->create($name);
17
18 5
        if (!$mutex->acquire($timeout)) {
19 1
            throw new RuntimeException("Unable to acquire mutex \"$name\".");
20
        }
21
22 4
        return $mutex;
23
    }
24
}
25