Passed
Pull Request — master (#20362)
by Wilmer
05:37
created

DbMutex::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\mutex;
9
10
use yii\base\InvalidConfigException;
11
use yii\db\Connection;
12
use yii\di\Instance;
13
14
/**
15
 * DbMutex is the base class for classes, which relies on database while implementing mutex "lock" mechanism.
16
 *
17
 * @see Mutex
18
 *
19
 * @author resurtm <[email protected]>
20
 * @since 2.0
21
 */
22
abstract class DbMutex extends Mutex
23
{
24
    /**
25
     * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
26
     * After the Mutex object is created, if you want to change this property, you should only assign
27
     * it with a DB connection object.
28
     * Starting from version 2.0.2, this can also be a configuration array for creating the object.
29
     */
30
    public $db = 'db';
31
32
33
    /**
34
     * Initializes generic database table based mutex implementation.
35
     * @throws InvalidConfigException if [[db]] is invalid.
36
     */
37
    public function init()
38
    {
39
        parent::init();
40
        $this->db = Instance::ensure($this->db, Connection::class);
41
    }
42
}
43