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

MutexFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createAndAcquire() 0 7 2
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