Passed
Push — master ( 81a026...4afd7b )
by ma
01:46
created

Singleton::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
1
<?php
2
namespace tinymeng\tools\core;
3
4
/**
5
 * 单例
6
 */
7
trait Singleton
8
{
9
    private $config;
10
11
    /**
12
     * @var null
13
     */
14
    private static $instance = null;
15
16
    public function __construct($config=null){
17
        $this->config = $config;
18
    }
19
20
    private function __clone(){}
21
22
    public function __sleep(): array
23
    {
24
        //重写__sleep方法,将返回置空,防止序列化反序列化获得新的对象
25
        return [];
26
    }
27
28
    protected static function init($gateway, $config=null)
0 ignored issues
show
Unused Code introduced by
The parameter $gateway is not used and could be removed. ( Ignorable by Annotation )

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

28
    protected static function init(/** @scrutinizer ignore-unused */ $gateway, $config=null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        if (!self::$instance instanceof static) {
31
            self::$instance = new static($config);
0 ignored issues
show
Documentation Bug introduced by
It seems like new static($config) of type tinymeng\tools\core\Singleton is incompatible with the declared type null of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        }
33
        return self::$instance;
34
    }
35
36
    /**
37
     * Description:  __callStatic
38
     * @author: JiaMeng <[email protected]>
39
     * Updater:
40
     * @param $gateway
41
     * @param $config
42
     * @return mixed
43
     */
44
    public static function __callStatic($gateway, $config=null)
45
    {
46
        return self::init($gateway, ...$config);
0 ignored issues
show
Bug introduced by
$config is expanded, but the parameter $config of tinymeng\tools\core\Singleton::init() does not expect variable arguments. ( Ignorable by Annotation )

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

46
        return self::init($gateway, /** @scrutinizer ignore-type */ ...$config);
Loading history...
47
    }
48
49
}
50