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.

LocalAutoLock   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C lock() 0 51 13
1
<?php
2
namespace PhpBoot\Lock;
3
4
/**
5
 * 自动加锁
6
 *
7
 * 使用
8
 */
9
class LocalAutoLock
10
{
11
    static function lock($key, $seconds, callable $success, callable $error=null){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
        $key = 'lock:'.$key;
13
        if(function_exists('apc_add')){
14
            $lock = new ApcLock();
15
        }else{
16
            $lock = new FileLock();
17
        }
18
        try{
19
            if(!isset(self::$currentLock[$key])){
20
                self::$currentLock[$key] = 0;
21
            }
22
            if(self::$currentLock[$key] == 0){  //未加锁
23
                if(!$lock->lock($key, $seconds)){ //加锁失败
24
                    if($error){
25
                        return $error();
26
                    }
27
                    return;
28
                }
29
            }
30
            //嵌套加锁
31
            self::$currentLock[$key]++;
32
        }catch (\Exception $e){
33
            if($error){
34
                return $error();
35
            }
36
            return;
37
        }
38
        $res = null;
39
        try{
40
            $res = $success();
41
        }catch (\Exception $e){
42
            self::$currentLock[$key]--;
43
            if(self::$currentLock[$key] == 0){
44
                try{
45
                    $lock->unlock($key);
46
                }catch (\Exception $e){
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
47
48
                }
49
            }
50
            throw $e;
51
        }
52
        self::$currentLock[$key]--;
53
        if(self::$currentLock[$key] == 0){
54
            try{
55
                $lock->unlock($key);
56
            }catch (\Exception $e){
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
57
58
            }
59
        }
60
        return $res;
61
    }
62
63
    private $cache=[];
64
    static private $currentLock=[];
65
}