Passed
Push — master ( c1e721...8ec156 )
by 世昌
02:05
created

EventRunner   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
B call() 0 30 11
1
<?php
2
3
namespace suda\application;
4
5
6
/**
7
 * 系统事件
8
 */
9
class EventRunner
10
{
11
    /**
12
     * 可执行器
13
     *
14
     * @var callback
15
     */
16
    protected $runnable;
17
18
    /**
19
     * 初始化
20
     *
21
     * @param callback $runnable
22
     */
23
    public function __construct($runnable) {
24
        $this->runnable = $runnable;
25
    }
26
27
    public function call(array &$args)
28
    {
29
        if (conf('hook.enable', true) == false) {
30
            debug()->warning(__('hook.enable == false refuse run command'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

30
            debug()->warning(/** @scrutinizer ignore-call */ __('hook.enable == false refuse run command'));
Loading history...
31
            return null;
32
        }
33
        if (is_string($command)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $command seems to be never defined.
Loading history...
34
            if (preg_match('/^(debug)|d\=/', $command)) {
35
                if (conf('debug')) {
0 ignored issues
show
Bug introduced by
The call to conf() has too few arguments starting with default. ( Ignorable by Annotation )

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

35
                if (/** @scrutinizer ignore-call */ conf('debug')) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
36
                    return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args);
0 ignored issues
show
Bug introduced by
The type suda\application\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
                }
38
            } elseif (preg_match('/^(normal)|n\=/', $command)) {
39
                if (conf('debug') == false) {
40
                    return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args);
41
                }
42
            } elseif (preg_match('/^is?\:(.+?)\=/', $command, $matchs)) {
43
                $module = $matchs[1];
44
                if (app()->getActiveModule() == app()->getModuleFullName($module)) {
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

44
                if (/** @scrutinizer ignore-call */ app()->getActiveModule() == app()->getModuleFullName($module)) {
Loading history...
45
                    return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args);
46
                }
47
            } elseif (preg_match('/^(?:reachable)|r\:(.+?)\=/', $command, $matchs)) {
48
                $module = $matchs[1];
49
                if (app()->isModuleReachable($module)) {
50
                    return (new Command(preg_replace('/^.+?\=/', '', $command)))->exec($args);
51
                }
52
            } else {
53
                return (new Command($command))->exec($args);
54
            }
55
        } else {
56
            return (new Command($command))->exec($args);
57
        }
58
    }
59
}
60