GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bbf2ff...d7ffda )
by Robert
12:47
created

MysqlMutex::hashLockName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\mutex;
9
10
use yii\base\InvalidConfigException;
11
12
/**
13
 * MysqlMutex implements mutex "lock" mechanism via MySQL locks.
14
 *
15
 * Application configuration example:
16
 *
17
 * ```
18
 * [
19
 *     'components' => [
20
 *         'db' => [
21
 *             'class' => 'yii\db\Connection',
22
 *             'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
23
 *         ]
24
 *         'mutex' => [
25
 *             'class' => 'yii\mutex\MysqlMutex',
26
 *         ],
27
 *     ],
28
 * ]
29
 * ```
30
 *
31
 * @see Mutex
32
 *
33
 * @author resurtm <[email protected]>
34
 * @since 2.0
35
 */
36
class MysqlMutex extends DbMutex
37
{
38
    /**
39
     * Initializes MySQL specific mutex component implementation.
40
     * @throws InvalidConfigException if [[db]] is not MySQL connection.
41
     */
42 10
    public function init()
43
    {
44 10
        parent::init();
45 10
        if ($this->db->driverName !== 'mysql') {
46
            throw new InvalidConfigException('In order to use MysqlMutex connection must be configured to use MySQL database.');
47
        }
48 10
    }
49
50
    /**
51
     * Acquires lock by given name.
52
     * @param string $name of the lock to be acquired.
53
     * @param int $timeout time (in seconds) to wait for lock to become released.
54
     * @return bool acquiring result.
55
     * @see http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_get-lock
56
     */
57 10
    protected function acquireLock($name, $timeout = 0)
58
    {
59
        return $this->db->useMaster(function ($db) use ($name, $timeout) {
60
            /** @var \yii\db\Connection $db */
61 10
            return (bool) $db->createCommand(
62 10
                'SELECT GET_LOCK(:name, :timeout)',
63 10
                [':name' => $this->hashLockName($name), ':timeout' => $timeout]
64 10
            )->queryScalar();
65 10
        });
66
    }
67
68
    /**
69
     * Releases lock by given name.
70
     * @param string $name of the lock to be released.
71
     * @return bool release result.
72
     * @see http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock
73
     */
74
    protected function releaseLock($name)
75
    {
76 10
        return $this->db->useMaster(function ($db) use ($name) {
77
            /** @var \yii\db\Connection $db */
78 10
            return (bool) $db->createCommand(
79 10
                'SELECT RELEASE_LOCK(:name)',
80 10
                [':name' => $this->hashLockName($name)]
81 10
            )->queryScalar();
82 10
        });
83
    }
84
85
    /**
86
     * Generate hash for lock name to avoid exceeding lock name length limit.
87
     *
88
     * @param string $name
89
     * @return string
90
     * @since 2.0.16
91
     * @see https://github.com/yiisoft/yii2/pull/16836
92
     */
93 10
    protected function hashLockName($name) {
94 10
        return sha1($name);
95
    }
96
}
97