Passed
Push — master ( 3354b2...c3d752 )
by 世昌
01:43
created
nebula/application/Config.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Config
12 12
 {
13
-    public $config=[];
13
+    public $config = [];
14 14
 
15
-    public function load(string $path, array $extra =[])
15
+    public function load(string $path, array $extra = [])
16 16
     {
17 17
         $data = $this->loadConfig($path, $extra);
18 18
         if ($data) {
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
         }
21 21
     }
22 22
 
23
-    public function loadConfig(string $path, array $extra =[]):?array
23
+    public function loadConfig(string $path, array $extra = []): ?array
24 24
     {
25
-        $data=null;
25
+        $data = null;
26 26
         if (!file_exists($path)) {
27
-            $path =$this->resolve($path);
27
+            $path = $this->resolve($path);
28 28
         }
29 29
         if ($path) {
30 30
             $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
                         throw new YamlException("parse yaml config error : missing yaml extension or spyc", 1);
40 40
                     }
41 41
                     $content = file_get_contents($path);
42
-                    $content =$this->parseValue($content, $extra);
42
+                    $content = $this->parseValue($content, $extra);
43 43
                     $data = \call_user_func_array($name, [$content]);
44 44
                     break;
45 45
                 case 'php':
@@ -47,15 +47,15 @@  discard block
 block discarded – undo
47 47
                     break;
48 48
                 case 'ini':
49 49
                     $content = file_get_contents($path);
50
-                    $content =$this->parseValue($content, $extra);
51
-                    $data =  \parse_ini_string($content, true);
50
+                    $content = $this->parseValue($content, $extra);
51
+                    $data = \parse_ini_string($content, true);
52 52
                     break;
53 53
                 case 'json':
54 54
                 default:
55 55
                     $content = file_get_contents($path);
56
-                    $content =$this->parseValue($content, $extra);
56
+                    $content = $this->parseValue($content, $extra);
57 57
                     $data = json_decode($content, true);
58
-                    if (json_last_error()!==JSON_ERROR_NONE) {
58
+                    if (json_last_error() !== JSON_ERROR_NONE) {
59 59
                         throw new JSONException(json_last_error());
60 60
                     }
61 61
             }
@@ -63,22 +63,22 @@  discard block
 block discarded – undo
63 63
         return $data;
64 64
     }
65 65
 
66
-    protected function parseValue(string $content, array $extra =[]):string
66
+    protected function parseValue(string $content, array $extra = []):string
67 67
     {
68
-        return preg_replace_callback('/\$\{(.+?)\}/', function ($matchs) use ($extra) {
68
+        return preg_replace_callback('/\$\{(.+?)\}/', function($matchs) use ($extra) {
69 69
             $name = $matchs[1];
70 70
             $value = $matchs[0];
71
-            if (($value = ArrayDotAccess::get($extra, $name, null))!==null) {
71
+            if (($value = ArrayDotAccess::get($extra, $name, null)) !== null) {
72 72
             } elseif (defined($name)) {
73 73
                 $value = constant($name);
74 74
             } else {
75 75
                 $value = $this->get($name, $value);
76 76
             }
77
-            return is_string($value)?trim(json_encode($value), '"'):$value;
77
+            return is_string($value) ?trim(json_encode($value), '"') : $value;
78 78
         }, $content);
79 79
     }
80 80
 
81
-    public static function resolve(string $path):?string
81
+    public static function resolve(string $path): ?string
82 82
     {
83 83
         if (file_exists($path)) {
84 84
             return $path;
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
             } else {
90 90
                 $basepath = pathinfo($path, PATHINFO_FILENAME);
91 91
             }
92
-            if (file_exists($conf = $basepath.'.yml')  || file_exists($conf = $basepath.'.yaml')) {
92
+            if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) {
93 93
                 if (function_exists('yaml_parse') || class_exists('Spyc')) {
94 94
                     return $conf;
95 95
                 }
96 96
             }
97
-            if (file_exists($conf=$basepath.'.json')) {
97
+            if (file_exists($conf = $basepath.'.json')) {
98 98
                 return $conf;
99
-            } elseif (file_exists($conf=$basepath.'.php')) {
99
+            } elseif (file_exists($conf = $basepath.'.php')) {
100 100
                 return $conf;
101
-            } elseif (file_exists($conf=$basepath.'.ini')) {
101
+            } elseif (file_exists($conf = $basepath.'.ini')) {
102 102
                 return $conf;
103 103
             }
104 104
         }
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
 
113 113
     public function assign(array $config)
114 114
     {
115
-        return $this->config=array_merge($this->config, $config);
115
+        return $this->config = array_merge($this->config, $config);
116 116
     }
117 117
 
118
-    public function get(string $name=null, $default=null)
118
+    public function get(string $name = null, $default = null)
119 119
     {
120 120
         if (is_null($name)) {
121 121
             return $this->config;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         return ArrayDotAccess::get($this->config, $name, $default);
124 124
     }
125 125
 
126
-    public function set(string $name, $value, $combine=null)
126
+    public function set(string $name, $value, $combine = null)
127 127
     {
128 128
         return ArrayDotAccess::set($this->config, $name, $value, $combine);
129 129
     }
Please login to merge, or discard this patch.