Completed
Push — master ( d61801...46edea )
by Biao
05:21
created

Context::delete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Hhxsv5\LaravelS\Swoole\Coroutine;
4
5
use Swoole\Coroutine;
6
7
class Context
8
{
9
    protected static $box = [];
10
11
    public static function get($key)
12
    {
13
        $cid = Coroutine::getCid();
0 ignored issues
show
Bug introduced by
The method getCid() does not exist on Swoole\Coroutine. Did you maybe mean getuid()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        /** @scrutinizer ignore-call */ 
14
        $cid = Coroutine::getCid();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
14
        if ($cid < 0) {
15
            return null;
16
        }
17
        if (isset(self::$box[$cid][$key])) {
18
            return self::$box[$cid][$key];
19
        }
20
        return null;
21
    }
22
23
    public static function put($key, $item)
24
    {
25
        $cid = Coroutine::getCid();
26
        if ($cid > 0) {
27
            self::$box[$cid][$key] = $item;
28
        }
29
    }
30
31
    public static function delete($key = null)
32
    {
33
        $cid = Coroutine::getCid();
34
        if ($cid > 0) {
35
            if ($key) {
36
                unset(self::$box[$cid][$key]);
37
            } else {
38
                unset(self::$box[$cid]);
39
            }
40
        }
41
    }
42
43
    public static function inCoroutine()
44
    {
45
        return class_exists('Swoole\Coroutine', false) && Coroutine::getCid() > 0;
46
    }
47
}