majiameng /
tools
| 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=[]){ |
||||
| 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=[]) |
||||
|
0 ignored issues
–
show
|
|||||
| 29 | { |
||||
| 30 | if (!self::$instance instanceof static) { |
||||
| 31 | self::$instance = new static($config); |
||||
|
0 ignored issues
–
show
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 | * @param $gateway |
||||
| 39 | * @param array $config |
||||
| 40 | * @return Singleton|null |
||||
| 41 | *@author: JiaMeng <[email protected]> |
||||
| 42 | * Updater: |
||||
| 43 | */ |
||||
| 44 | public static function __callStatic($gateway, array $config=[]) |
||||
| 45 | { |
||||
| 46 | return self::init($gateway, ...$config); |
||||
|
0 ignored issues
–
show
$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
Loading history...
|
|||||
| 47 | } |
||||
| 48 | |||||
| 49 | } |
||||
| 50 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.