@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * 可执行命令表达式 |
13 | 13 | * |
14 | 14 | */ |
15 | -class Runnable { |
|
15 | +class Runnable { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * 运行对象 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | protected $target; |
23 | 23 | |
24 | - public function __construct($runnable, array $parameter=[]) { |
|
24 | + public function __construct($runnable, array $parameter = []) { |
|
25 | 25 | $this->target = TargetBuilder::build($runnable, $parameter); |
26 | 26 | } |
27 | 27 |
@@ -5,7 +5,7 @@ |
||
5 | 5 | * 可执行命令表目标 |
6 | 6 | * |
7 | 7 | */ |
8 | -abstract class RunnableTarget { |
|
8 | +abstract class RunnableTarget { |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * 参数 |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | protected $function; |
19 | 19 | |
20 | - public function __construct(string $name, array $parameter =[]) { |
|
20 | + public function __construct(string $name, array $parameter = []) { |
|
21 | 21 | $this->setParameter($parameter); |
22 | 22 | $this->function = $name; |
23 | 23 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | protected $closure; |
19 | 19 | |
20 | - public function __construct(Closure $closure, array $parameter =[]) { |
|
20 | + public function __construct(Closure $closure, array $parameter = []) { |
|
21 | 21 | $this->closure = $closure; |
22 | 22 | $this->parameter = $parameter; |
23 | 23 | $this->name = 'Closure object()'; |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * @param string $method |
47 | 47 | * @param array $parameter |
48 | 48 | */ |
49 | - public function __construct($object, ?array $constructParameter=null, string $method, array $parameter = []) |
|
49 | + public function __construct($object, ?array $constructParameter = null, string $method, array $parameter = []) |
|
50 | 50 | { |
51 | 51 | $this->object = $object; |
52 | 52 | $this->constructParameter = $constructParameter; |
53 | 53 | $this->method = $method; |
54 | 54 | $this->parameter = $parameter; |
55 | 55 | $static = $this->isStatic() ? '->' : '::'; |
56 | - $name = \is_object($object)? \get_class($object) : $object; |
|
56 | + $name = \is_object($object) ? \get_class($object) : $object; |
|
57 | 57 | $this->name = $name.$static.$method; |
58 | 58 | } |
59 | 59 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return object|null 动态类可获取 |
64 | 64 | */ |
65 | - public function getObjectInstance():?object |
|
65 | + public function getObjectInstance(): ?object |
|
66 | 66 | { |
67 | 67 | if (\is_object($this->object)) { |
68 | 68 | return $this->object; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | if (!is_null($this->requireFile) && !\class_exists($this->object)) { |
74 | 74 | require_once $this->requireFile; |
75 | 75 | } |
76 | - $classRef= new ReflectionClass($this->object); |
|
76 | + $classRef = new ReflectionClass($this->object); |
|
77 | 77 | return $classRef->newInstanceArgs($this->constructParameter); |
78 | 78 | } |
79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | if ($this->isStatic() || \is_object($this->object)) { |
84 | 84 | $this->runnableTarget = [$this->object, $this->method]; |
85 | 85 | } |
86 | - $this->runnableTarget = [$this->getObjectInstance() ?? $this->object, $this->method]; |
|
86 | + $this->runnableTarget = [$this->getObjectInstance() ?? $this->object, $this->method]; |
|
87 | 87 | } |
88 | 88 | return $this->runnableTarget; |
89 | 89 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | $requireFile = ''; |
54 | 54 | if ($fileStart > 0) { |
55 | - $requireFile = substr($command, $fileStart+1); |
|
55 | + $requireFile = substr($command, $fileStart + 1); |
|
56 | 56 | $command = substr($command, 0, $fileStart); |
57 | 57 | } |
58 | 58 | // for parameter list |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | $dynmicsMethod; |
65 | 65 | $parameter = self::buildParameter($parameter); |
66 | 66 | if ($methodStart > 0) { |
67 | - $splitLength = $splitLength > 0 ? 1:2; |
|
67 | + $splitLength = $splitLength > 0 ? 1 : 2; |
|
68 | 68 | $methodName = substr($command, $methodStart + $splitLength); |
69 | 69 | $command = substr($command, 0, $methodStart); |
70 | 70 | list($className, $constructParameter) = self::splitParameter($command); |
71 | 71 | $constructParameter = self::buildParameter($constructParameter); |
72 | - $target = new MethodTarget($className, $dynmicsMethod? $constructParameter :null, $methodName, $parameter); |
|
72 | + $target = new MethodTarget($className, $dynmicsMethod ? $constructParameter : null, $methodName, $parameter); |
|
73 | 73 | } else { |
74 | 74 | $target = new FunctionTarget(self::buildName($command), $parameter); |
75 | 75 | } |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | if (is_null($parameter)) { |
87 | 87 | return new $classRelName; |
88 | 88 | } |
89 | - $parameters=self::buildParameter($parameter); |
|
90 | - $classRef= new ReflectionClass($classRelName); |
|
89 | + $parameters = self::buildParameter($parameter); |
|
90 | + $classRef = new ReflectionClass($classRelName); |
|
91 | 91 | return $classRef->newInstanceArgs($parameters); |
92 | 92 | } |
93 | 93 | |
@@ -96,18 +96,18 @@ discard block |
||
96 | 96 | if (preg_match('/^[\w\\\\\/.]+$/', $name) !== 1) { |
97 | 97 | throw new InvalidNameException(\sprintf('invaild name: %s ', $name)); |
98 | 98 | } |
99 | - return str_replace(['.','/'], '\\', $name); |
|
99 | + return str_replace(['.', '/'], '\\', $name); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | private static function splitParameter(string $command):array |
103 | 103 | { |
104 | 104 | $parameter = null; |
105 | - if (strrpos($command, ')') === strlen($command) -1) { |
|
105 | + if (strrpos($command, ')') === strlen($command) - 1) { |
|
106 | 106 | $paramStart = strpos($command, '('); |
107 | 107 | $parameter = substr($command, $paramStart + 1, strlen($command) - $paramStart - 2); |
108 | 108 | $command = substr($command, 0, $paramStart); |
109 | 109 | } |
110 | - return [$command,$parameter]; |
|
110 | + return [$command, $parameter]; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | private static function buildParameter(?string $parameter) |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | if (strpos($value, ':') === 0) { |
127 | 127 | $value = base64_decode(substr($value, 1)); |
128 | 128 | } |
129 | - if ($prefix ==='=j' || $prefix ==='=json') { |
|
129 | + if ($prefix === '=j' || $prefix === '=json') { |
|
130 | 130 | $params = json_decode($value); |
131 | 131 | if (json_last_error() === JSON_ERROR_NONE) { |
132 | 132 | return $params; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } else { |
143 | 143 | $params = explode(',', trim($param, ',')); |
144 | 144 | foreach ($params as $index=>$value) { |
145 | - $params[$index]=trim($value); |
|
145 | + $params[$index] = trim($value); |
|
146 | 146 | } |
147 | 147 | return $params; |
148 | 148 | } |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @var string|null |
17 | 17 | */ |
18 | - protected $requireFile=null; |
|
18 | + protected $requireFile = null; |
|
19 | 19 | |
20 | - public function __construct(string $path, array $parameter =[]) { |
|
20 | + public function __construct(string $path, array $parameter = []) { |
|
21 | 21 | $this->setRequireFile($path); |
22 | 22 | $this->setParameter($parameter); |
23 | 23 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function setRequireFile($requireFile) |
48 | 48 | { |
49 | 49 | $this->requireFile = $requireFile; |
50 | - $this->name ='@'.$requireFile; |
|
50 | + $this->name = '@'.$requireFile; |
|
51 | 51 | return $this; |
52 | 52 | } |
53 | 53 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $args = $this->getParameter(); |
74 | 74 | } |
75 | 75 | array_unshift($args, $this->requireFile); |
76 | - $_SERVER['argv']=$args; |
|
77 | - $_SERVER['args']=count($args); |
|
76 | + $_SERVER['argv'] = $args; |
|
77 | + $_SERVER['args'] = count($args); |
|
78 | 78 | return include $this->requireFile; |
79 | 79 | } |
80 | 80 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @var array |
13 | 13 | */ |
14 | - protected $attribute=[]; |
|
14 | + protected $attribute = []; |
|
15 | 15 | |
16 | 16 | public function addAttribute(array $value) |
17 | 17 | { |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | protected function analyse(array $context) |
22 | 22 | { |
23 | 23 | $replace = []; |
24 | - $attach =[] ; |
|
24 | + $attach = []; |
|
25 | 25 | foreach ($context as $key => $val) { |
26 | - if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && ! $val instanceof \Exception) { |
|
27 | - $replace['{' . $key . '}'] = $val; |
|
26 | + if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && !$val instanceof \Exception) { |
|
27 | + $replace['{'.$key.'}'] = $val; |
|
28 | 28 | } else { |
29 | 29 | $attach[$key] = $val; |
30 | 30 | } |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | |
35 | 35 | public function interpolate(string $message, array $context, array $attribute) |
36 | 36 | { |
37 | - list($attach, $replace) = $this->analyse($context); |
|
37 | + list($attach, $replace) = $this->analyse($context); |
|
38 | 38 | $attribute = array_merge($this->attribute, $attribute); |
39 | 39 | foreach ($attribute as $key => $val) { |
40 | - $replace['%' . $key . '%'] = $val; |
|
40 | + $replace['%'.$key.'%'] = $val; |
|
41 | 41 | } |
42 | 42 | $message = strtr($message, $replace); |
43 | 43 | $attachInfo = ''; |
44 | 44 | foreach ($attach as $name => $value) { |
45 | 45 | $attachInfo = $name.' = '; |
46 | 46 | if ($value instanceof AttachValueInterface) { |
47 | - $attachInfo.= $value->getLogAttach().PHP_EOL; |
|
47 | + $attachInfo .= $value->getLogAttach().PHP_EOL; |
|
48 | 48 | } else { |
49 | - $attachInfo.= DumpTrait::parameterToString($value).PHP_EOL; |
|
49 | + $attachInfo .= DumpTrait::parameterToString($value).PHP_EOL; |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | if (strlen($attachInfo) > 0) { |
@@ -6,7 +6,7 @@ |
||
6 | 6 | */ |
7 | 7 | interface DumpInterface |
8 | 8 | { |
9 | - public static function parameterToString($object, int $deep=2); |
|
9 | + public static function parameterToString($object, int $deep = 2); |
|
10 | 10 | public static function dumpException(\Exception $e); |
11 | - public static function dumpTrace(array $backtrace, bool $str=true, string $perfix=''); |
|
11 | + public static function dumpTrace(array $backtrace, bool $str = true, string $perfix = ''); |
|
12 | 12 | } |