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

MutexFactory::createAndAcquire()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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