Completed
Push — 6.0 ( a46922...a4d0a5 )
by liu
06:54 queued 03:44
created

App   F

Complexity

Total Complexity 69

Size/Duplication

Total Lines 610
Duplicated Lines 0 %

Test Coverage

Coverage 93.17%

Importance

Changes 0
Metric Value
eloc 147
dl 0
loc 610
ccs 150
cts 161
cp 0.9317
rs 2.88
c 0
b 0
f 0
wmc 69

35 Methods

Rating   Name   Duplication   Size   Complexity  
A debug() 0 4 1
A getBeginMem() 0 3 1
A getConfigExt() 0 3 1
A setRuntimePath() 0 3 1
A getAppPath() 0 3 1
A bootService() 0 4 2
A register() 0 21 6
A isDebug() 0 3 1
A __construct() 0 15 3
A getNamespace() 0 3 1
A getRuntimePath() 0 3 1
A getConfigPath() 0 3 1
A getThinkPath() 0 3 1
A getBasePath() 0 3 1
A setAppPath() 0 3 1
A getBeginTime() 0 3 1
A version() 0 3 1
A getRootPath() 0 3 1
A setNamespace() 0 4 1
A getService() 0 6 2
A serialize() 0 7 1
A unserialize() 0 7 1
A runningInConsole() 0 3 2
A parseName() 0 10 3
A initialized() 0 3 1
A factory() 0 9 3
A initialize() 0 38 3
A boot() 0 4 1
A parseClass() 0 8 2
B load() 0 30 7
A loadEvent() 0 12 4
A loadLangPack() 0 15 3
A getDefaultRootPath() 0 5 1
A debugModeInit() 0 16 6
A classBaseName() 0 4 2

How to fix   Complexity   

Complex Class

Complex classes like App often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use App, and based on these observations, apply Extract Interface, too.

1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think;
14
15
use Opis\Closure\SerializableClosure;
16
use think\exception\ClassNotFoundException;
17
use think\initializer\BootService;
18
use think\initializer\Error;
19
use think\initializer\RegisterService;
20
21
/**
22
 * App 基础类
23
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
24
class App extends Container
25
{
26
    const VERSION = '6.0.0RC3';
27
28
    /**
29
     * 应用调试模式
30
     * @var bool
31
     */
32
    protected $appDebug = false;
33
34
    /**
35
     * 应用开始时间
36
     * @var float
37
     */
38
    protected $beginTime;
39
40
    /**
41
     * 应用内存初始占用
42
     * @var integer
43
     */
44
    protected $beginMem;
45
46
    /**
47
     * 当前应用类库命名空间
48
     * @var string
49
     */
50
    protected $namespace = 'app';
51
52
    /**
53
     * 应用根目录
54
     * @var string
55
     */
56
    protected $rootPath = '';
57
58
    /**
59
     * 框架目录
60
     * @var string
61
     */
62
    protected $thinkPath = '';
63
64
    /**
65
     * 应用目录
66
     * @var string
67
     */
68
    protected $appPath = '';
69
70
    /**
71
     * Runtime目录
72
     * @var string
73
     */
74
    protected $runtimePath = '';
75
76
    /**
77
     * 配置后缀
78
     * @var string
79
     */
80
    protected $configExt = '.php';
81
82
    /**
83
     * 应用初始化器
84
     * @var array
85
     */
86
    protected $initializers = [
87
        Error::class,
88
        RegisterService::class,
89
        BootService::class,
90
    ];
91
92
    /**
93
     * 注册的系统服务
94
     * @var array
95
     */
96
    protected $services = [];
97
98
    /**
99
     * 初始化
100
     * @var bool
101
     */
102
    protected $initialized = false;
103
104
    /**
105
     * 架构方法
106
     * @access public
107
     * @param string $rootPath 应用根目录
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
108
     */
109 18
    public function __construct(string $rootPath = '')
110
    {
111 18
        $this->thinkPath   = dirname(__DIR__) . DIRECTORY_SEPARATOR;
112 18
        $this->rootPath    = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath();
113 18
        $this->appPath     = $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
114 18
        $this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR;
115
116 18
        if (is_file($this->appPath . 'provider.php')) {
117 1
            $this->bind(include $this->appPath . 'provider.php');
118
        }
119
120 18
        static::setInstance($this);
121
122 18
        $this->instance('app', $this);
123 18
        $this->instance('think\Container', $this);
124 18
    }
125
126
    /**
127
     * 注册服务
128
     * @access public
129
     * @param Service|string $service 服务
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
130
     * @param bool           $force   强制重新注册
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
131
     * @return Service|null
132
     */
133 1
    public function register($service, bool $force = false)
134
    {
135 1
        $registered = $this->getService($service);
136
137 1
        if ($registered && !$force) {
138 1
            return $registered;
139
        }
140
141 1
        if (is_string($service)) {
142 1
            $service = new $service($this);
143
        }
144
145 1
        if (method_exists($service, 'register')) {
146 1
            $service->register();
147
        }
148
149 1
        if (property_exists($service, 'bind')) {
150 1
            $this->bind($service->bind);
151
        }
152
153 1
        $this->services[] = $service;
154 1
    }
155
156
    /**
157
     * 执行服务
158
     * @access public
159
     * @param Service $service 服务
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
160
     * @return mixed
161
     */
162 1
    public function bootService($service)
163
    {
164 1
        if (method_exists($service, 'boot')) {
165 1
            return $this->invoke([$service, 'boot']);
166
        }
167 1
    }
168
169
    /**
170
     * 获取服务
171
     * @param string|Service $service
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
172
     * @return Service|null
173
     */
174 1
    public function getService($service)
175
    {
176 1
        $name = is_string($service) ? $service : get_class($service);
177
        return array_values(array_filter($this->services, function ($value) use ($name) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
178 1
            return $value instanceof $name;
179 1
        }, ARRAY_FILTER_USE_BOTH))[0] ?? null;
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
180
    }
181
182
    /**
183
     * 开启应用调试模式
184
     * @access public
185
     * @param bool $debug 开启应用调试模式
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
186
     * @return $this
187
     */
188 2
    public function debug(bool $debug = true)
189
    {
190 2
        $this->appDebug = $debug;
191 2
        return $this;
192
    }
193
194
    /**
195
     * 是否为调试模式
196
     * @access public
197
     * @return bool
198
     */
199 7
    public function isDebug(): bool
200
    {
201 7
        return $this->appDebug;
202
    }
203
204
    /**
205
     * 设置应用命名空间
206
     * @access public
207
     * @param string $namespace 应用命名空间
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
208
     * @return $this
209
     */
210 7
    public function setNamespace(string $namespace)
211
    {
212 7
        $this->namespace = $namespace;
213 7
        return $this;
214
    }
215
216
    /**
217
     * 获取应用类库命名空间
218
     * @access public
219
     * @return string
220
     */
221 1
    public function getNamespace(): string
222
    {
223 1
        return $this->namespace;
224
    }
225
226
    /**
227
     * 获取框架版本
228
     * @access public
229
     * @return string
230
     */
231 1
    public function version(): string
232
    {
233 1
        return static::VERSION;
234
    }
235
236
    /**
237
     * 获取应用根目录
238
     * @access public
239
     * @return string
240
     */
241 1
    public function getRootPath(): string
242
    {
243 1
        return $this->rootPath;
244
    }
245
246
    /**
247
     * 获取应用基础目录
248
     * @access public
249
     * @return string
250
     */
251 10
    public function getBasePath(): string
252
    {
253 10
        return $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
254
    }
255
256
    /**
257
     * 获取当前应用目录
258
     * @access public
259
     * @return string
260
     */
261 7
    public function getAppPath(): string
262
    {
263 7
        return $this->appPath;
264
    }
265
266
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $path should have a doc-comment as per coding-style.
Loading history...
267
     * 设置应用目录
268
     * @param $path
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
269
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
270 6
    public function setAppPath($path)
271
    {
272 6
        $this->appPath = $path;
273 6
    }
274
275
    /**
276
     * 获取应用运行时目录
277
     * @access public
278
     * @return string
279
     */
280 7
    public function getRuntimePath(): string
281
    {
282 7
        return $this->runtimePath;
283
    }
284
285
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $path should have a doc-comment as per coding-style.
Loading history...
286
     * 设置runtime目录
287
     * @param $path
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
288
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
289 6
    public function setRuntimePath($path)
290
    {
291 6
        $this->runtimePath = $path;
292 6
    }
293
294
    /**
295
     * 获取核心框架目录
296
     * @access public
297
     * @return string
298
     */
299 1
    public function getThinkPath(): string
300
    {
301 1
        return $this->thinkPath;
302
    }
303
304
    /**
305
     * 获取应用配置目录
306
     * @access public
307
     * @return string
308
     */
309 10
    public function getConfigPath(): string
310
    {
311 10
        return $this->rootPath . 'config' . DIRECTORY_SEPARATOR;
312
    }
313
314
    /**
315
     * 获取配置后缀
316
     * @access public
317
     * @return string
318
     */
319 9
    public function getConfigExt(): string
320
    {
321 9
        return $this->configExt;
322
    }
323
324
    /**
325
     * 获取应用开启时间
326
     * @access public
327
     * @return float
328
     */
329 1
    public function getBeginTime(): float
330
    {
331 1
        return $this->beginTime;
332
    }
333
334
    /**
335
     * 获取应用初始内存占用
336
     * @access public
337
     * @return integer
338
     */
339 1
    public function getBeginMem(): int
340
    {
341 1
        return $this->beginMem;
342
    }
343
344
    /**
345
     * 初始化应用
346
     * @access public
347
     * @return $this
348
     */
349 1
    public function initialize()
350
    {
351 1
        $this->initialized = true;
352
353 1
        $this->beginTime = microtime(true);
354 1
        $this->beginMem  = memory_get_usage();
355
356
        // 加载环境变量
357 1
        if (is_file($this->rootPath . '.env')) {
358 1
            $this->env->load($this->rootPath . '.env');
359
        }
360
361 1
        $this->configExt = $this->env->get('config_ext', '.php');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->env->get('config_ext', '.php') can also be of type boolean. However, the property $configExt is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
362
363
        // 加载全局初始化文件
364 1
        $this->load();
365
366 1
        $this->debugModeInit();
367
368
        // 加载框架默认语言包
369 1
        $langSet = $this->lang->defaultLangSet();
370
371 1
        $this->lang->load($this->thinkPath . 'lang' . DIRECTORY_SEPARATOR . $langSet . '.php');
372
373
        // 加载应用默认语言包
374 1
        $this->loadLangPack($langSet);
375
376
        // 监听AppInit
377 1
        $this->event->trigger('AppInit');
378
379 1
        date_default_timezone_set($this->config->get('app.default_timezone', 'Asia/Shanghai'));
0 ignored issues
show
Bug introduced by
It seems like $this->config->get('app....zone', 'Asia/Shanghai') can also be of type array; however, parameter $timezone_identifier of date_default_timezone_set() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

379
        date_default_timezone_set(/** @scrutinizer ignore-type */ $this->config->get('app.default_timezone', 'Asia/Shanghai'));
Loading history...
380
381
        // 初始化
382 1
        foreach ($this->initializers as $initializer) {
383 1
            $this->make($initializer)->init($this);
384
        }
385
386 1
        return $this;
387
    }
388
389
    /**
390
     * 是否初始化过
391
     * @return bool
392
     */
393 1
    public function initialized()
394
    {
395 1
        return $this->initialized;
396
    }
397
398
    /**
399
     * 加载语言包
400
     * @param string $langset 语言
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
401
     * @return void
402
     */
403 6
    public function loadLangPack($langset)
404
    {
405 6
        if (empty($langset)) {
406
            return;
407
        }
408
409
        // 加载系统语言包
410 6
        $files = glob($this->appPath . 'lang' . DIRECTORY_SEPARATOR . $langset . '.*');
411 6
        $this->lang->load($files);
0 ignored issues
show
Bug introduced by
It seems like $files can also be of type false; however, parameter $file of think\Lang::load() does only seem to accept array|string, maybe add an additional type check? ( Ignorable by Annotation )

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

411
        $this->lang->load(/** @scrutinizer ignore-type */ $files);
Loading history...
412
413
        // 加载扩展(自定义)语言包
414 6
        $list = $this->config->get('lang.extend_list', []);
415
416 6
        if (isset($list[$langset])) {
417
            $this->lang->load($list[$langset]);
418
        }
419 6
    }
420
421
    /**
422
     * 引导应用
423
     * @access public
424
     * @return void
425
     */
426 1
    public function boot(): void
427
    {
428
        array_walk($this->services, function ($service) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
429 1
            $this->bootService($service);
430 1
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
431 1
    }
432
433
    /**
434
     * 加载应用文件和配置
435
     * @access protected
436
     * @return void
437
     */
438 1
    protected function load(): void
439
    {
440 1
        $appPath = $this->getAppPath();
441
442 1
        if (is_file($appPath . 'common.php')) {
443 1
            include $appPath . 'common.php';
444
        }
445
446 1
        include $this->thinkPath . 'helper.php';
447
448 1
        $configPath = $this->getConfigPath();
449
450 1
        $files = [];
451
452 1
        if (is_dir($configPath)) {
453 1
            $files = glob($configPath . '*' . $this->configExt);
454
        }
455
456 1
        foreach ($files as $file) {
457
            $this->config->load($file, pathinfo($file, PATHINFO_FILENAME));
458
        }
459
460 1
        if (is_file($appPath . 'event.php')) {
461 1
            $this->loadEvent(include $appPath . 'event.php');
462
        }
463
464 1
        if (is_file($appPath . 'service.php')) {
465
            $services = include $appPath . 'service.php';
466
            foreach ($services as $service) {
467
                $this->register($service);
468
            }
469
        }
470 1
    }
471
472
    /**
473
     * 调试模式设置
474
     * @access protected
475
     * @return void
476
     */
477 1
    protected function debugModeInit(): void
478
    {
479
        // 应用调试模式
480 1
        if (!$this->appDebug) {
481 1
            $this->appDebug = $this->env->get('app_debug') ? true : false;
482 1
            ini_set('display_errors', 'Off');
483
        }
484
485 1
        if (!$this->runningInConsole()) {
486
            //重新申请一块比较大的buffer
487
            if (ob_get_level() > 0) {
488
                $output = ob_get_clean();
489
            }
490
            ob_start();
491
            if (!empty($output)) {
492
                echo $output;
493
            }
494
        }
495 1
    }
496
497
    /**
498
     * 注册应用事件
499
     * @access protected
500
     * @param array $event 事件数据
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
501
     * @return void
502
     */
503 2
    public function loadEvent(array $event): void
504
    {
505 2
        if (isset($event['bind'])) {
506 2
            $this->event->bind($event['bind']);
507
        }
508
509 2
        if (isset($event['listen'])) {
510 2
            $this->event->listenEvents($event['listen']);
511
        }
512
513 2
        if (isset($event['subscribe'])) {
514 2
            $this->event->subscribe($event['subscribe']);
515
        }
516 2
    }
517
518
    /**
519
     * 解析应用类的类名
520
     * @access public
521
     * @param string $layer 层名 controller model ...
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
522
     * @param string $name  类名
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
523
     * @return string
524
     */
525 1
    public function parseClass(string $layer, string $name): string
526
    {
527 1
        $name  = str_replace(['/', '.'], '\\', $name);
528 1
        $array = explode('\\', $name);
529 1
        $class = self::parseName(array_pop($array), 1);
530 1
        $path  = $array ? implode('\\', $array) . '\\' : '';
531
532 1
        return $this->namespace . '\\' . $layer . '\\' . $path . $class;
533
    }
534
535
    /**
536
     * 是否运行在命令行下
537
     * @return bool
538
     */
539 1
    public function runningInConsole()
540
    {
541 1
        return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg';
542
    }
543
544
    /**
545
     * 获取应用根目录
546
     * @access protected
547
     * @return string
548
     */
549 18
    protected function getDefaultRootPath(): string
550
    {
551 18
        $path = dirname(dirname(dirname(dirname($this->thinkPath))));
552
553 18
        return $path . DIRECTORY_SEPARATOR;
554
    }
555
556
    /**
557
     * 字符串命名风格转换
558
     * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
559
     * @access public
560
     * @param string  $name    字符串
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
561
     * @param integer $type    转换类型
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
562
     * @param bool    $ucfirst 首字母是否大写(驼峰规则)
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
563
     * @return string
564
     */
565 13
    public static function parseName(string $name = null, int $type = 0, bool $ucfirst = true): string
566
    {
567 13
        if ($type) {
568
            $name = preg_replace_callback('/_([a-zA-Z])/', function ($match) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
569 2
                return strtoupper($match[1]);
570 2
            }, $name);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
571 2
            return $ucfirst ? ucfirst($name) : lcfirst($name);
572
        }
573
574 12
        return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_"));
575
    }
576
577
    /**
578
     * 获取类名(不包含命名空间)
579
     * @access public
580
     * @param string|object $class
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
581
     * @return string
582
     */
583 1
    public static function classBaseName($class): string
584
    {
585 1
        $class = is_object($class) ? get_class($class) : $class;
586 1
        return basename(str_replace('\\', '/', $class));
587
    }
588
589
    /**
0 ignored issues
show
Coding Style introduced by
Parameter ...$args should have a doc-comment as per coding-style.
Loading history...
590
     * 创建工厂对象实例
591
     * @access public
592
     * @param string $name      工厂类名
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
593
     * @param string $namespace 默认命名空间
1 ignored issue
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
594
     * @param array  $args
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $args does not match actual variable name ...$args
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
595
     * @return mixed
596
     */
597 1
    public static function factory(string $name, string $namespace = '', ...$args)
598
    {
599 1
        $class = false !== strpos($name, '\\') ? $name : $namespace . ucwords($name);
600
601 1
        if (class_exists($class)) {
602 1
            return Container::getInstance()->invokeClass($class, $args);
603
        }
604
605 1
        throw new ClassNotFoundException('class not exists:' . $class, $class);
606
    }
607
608
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $data should have a doc-comment as per coding-style.
Loading history...
609
     * @param $data
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 14 spaces but found 1
Loading history...
610
     * @codeCoverageIgnore
611
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag value for @return tag indented incorrectly; expected 13 spaces but found 1
Loading history...
612
     */
613
    public static function serialize($data): string
614
    {
615
        SerializableClosure::enterContext();
616
        SerializableClosure::wrapClosures($data);
617
        $data = \serialize($data);
618
        SerializableClosure::exitContext();
619
        return $data;
620
    }
621
622
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
623
     * @param string $data
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 14 spaces but found 1
Loading history...
624
     * @codeCoverageIgnore
625
     * @return mixed|string
1 ignored issue
show
Coding Style introduced by
Tag value for @return tag indented incorrectly; expected 13 spaces but found 1
Loading history...
626
     */
627
    public static function unserialize(string $data)
628
    {
629
        SerializableClosure::enterContext();
630
        $data = \unserialize($data);
631
        SerializableClosure::unwrapClosures($data);
632
        SerializableClosure::exitContext();
633
        return $data;
634
    }
635
}
636