Passed
Pull Request — master (#31)
by Evgeniy
02:29
created

MutexFactory::createAndAcquire()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

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 7
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Mutex;
6
7
use RuntimeException;
8
9
abstract class MutexFactory implements MutexFactoryInterface
10
{
11
    final public function createAndAcquire(string $name, int $timeout = 0): MutexInterface
12
    {
13
        $mutex = $this->create($name);
14
        if (!$mutex->acquire($timeout)) {
15
            throw new RuntimeException("Unable to acquire mutex \"$name\".");
16
        }
17
        return $mutex;
18
    }
19
}
20