Test Failed
Push — master ( 5be5d8...a80515 )
by kill
03:34 queued 52s
created
function.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
     if (isset($arr['status']) && $type == 2) {
42 42
         $ret=$arr;
43
-    }
44
-    else {
43
+    } else {
45 44
         $ret['status']=$type;
46 45
         $ret['data']=$arr;
47 46
     }
@@ -323,8 +322,7 @@  discard block
 block discarded – undo
323 322
         if ($filters) {
324 323
             if (is_string($filters)) {
325 324
                 $filters=explode(',', $filters);
326
-            }
327
-            else if (is_array($filters)) {
325
+            } else if (is_array($filters)) {
328 326
                 foreach ($filters as $filter) {
329 327
                     $data=array_map_recursive($filter, $data); // 参数过滤
330 328
                 }
Please login to merge, or discard this patch.
core/helpers/Chaos.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -1,199 +1,199 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace puck\helpers;
3 3
 class Chaos {
4
-	public $GbToBigArray;
5
-	public $_pinyin;
6
-	public $string;
7
-	public $url='';
8
-	public $msg='';
9
-	public $action;
10
-	private $prefix;
4
+    public $GbToBigArray;
5
+    public $_pinyin;
6
+    public $string;
7
+    public $url='';
8
+    public $msg='';
9
+    public $action;
10
+    private $prefix;
11 11
 	
12 12
     function __construct() {
13
-		$this->_pinyin=new PinYin();
14
-	}
13
+        $this->_pinyin=new PinYin();
14
+    }
15 15
 
16 16
     /**
17 17
      * @param array $prefix
18 18
      */
19 19
     public function addPrefix(array $prefix) {
20 20
         $this->prefix=$prefix[array_rand($prefix)];
21
-	}
21
+    }
22 22
 
23 23
     public function clearPrefix() {
24 24
         $this->prefix='';
25
-	}
25
+    }
26 26
     public function get($str) {
27 27
         $this->cutting($str);
28 28
         $this->convert();
29 29
         $this->clearPrefix();
30 30
         return $this->msg;
31
-	}
31
+    }
32 32
 
33
-	//分离URL
34
-	private function cutting($str) {
33
+    //分离URL
34
+    private function cutting($str) {
35 35
 
36
-		if (preg_match("@(http://[^\\s]+)@i", $str, $result)) {
37
-			$this->url=$result[1];
38
-			$this->msg=$str=str_replace($this->url, '%%%%', $str);
39
-		} else {
40
-			$this->msg=$str;
41
-		}
42
-	}
36
+        if (preg_match("@(http://[^\\s]+)@i", $str, $result)) {
37
+            $this->url=$result[1];
38
+            $this->msg=$str=str_replace($this->url, '%%%%', $str);
39
+        } else {
40
+            $this->msg=$str;
41
+        }
42
+    }
43 43
 	
44 44
 	
45 45
 	
46
-	private function convert($method='msg') {
47
-		if ($method == 'msg' || $method == 'all') {
48
-			$this->msg=$this->setPinyin($this->msg);
49
-			$this->msg=$this->setRepeat($this->msg);
50
-			//$this->msg = $this->GbToBig($this->msg);
51
-			$this->msg=$this->setBlankness($this->msg);
46
+    private function convert($method='msg') {
47
+        if ($method == 'msg' || $method == 'all') {
48
+            $this->msg=$this->setPinyin($this->msg);
49
+            $this->msg=$this->setRepeat($this->msg);
50
+            //$this->msg = $this->GbToBig($this->msg);
51
+            $this->msg=$this->setBlankness($this->msg);
52 52
 			
53
-		}
54
-		if ($method == 'url' || $method == 'all') {
55
-			$this->url=$this->setChacha($this->url);
56
-		}
57
-		$this->msg=$this->prefix.str_replace('%%%%', $this->url, $this->msg);
58
-	}
53
+        }
54
+        if ($method == 'url' || $method == 'all') {
55
+            $this->url=$this->setChacha($this->url);
56
+        }
57
+        $this->msg=$this->prefix.str_replace('%%%%', $this->url, $this->msg);
58
+    }
59 59
 	
60
-	/**
61
-	 * @param string $url
62
-	 */
63
-	function setChacha($url) {
64
-		$url=strtolower($url);
65
-		$arr=array(
66
-			'a' => array('a', 'A', 'a', 'A', 'Α', 'А', 'α'),
67
-			'b' => array('b', 'B', 'b', 'B', 'Β', 'В', 'Ь'),
68
-			'c' => array('c', 'C', 'c', 'C', 'С', 'с'),
69
-			'd' => array('d', 'D', 'd', 'D'),
70
-			'e' => array('e', 'E', 'e', 'E', 'Ε', 'Е', 'е'),
71
-			'f' => array('f', 'F', 'f', 'F'),
72
-			'g' => array('g', 'G', 'g', 'G'),
73
-			'h' => array('h', 'H', 'h', 'H', 'Η', 'Н', 'н'),
74
-			'i' => array('i', 'I', 'i', 'I', 'Ι', 'Ⅰ'),
75
-			'j' => array('j', 'J', 'j', 'J'),
76
-			'k' => array('k', 'K', 'k', 'K', 'Κ', 'κ', 'к', 'К'),
77
-			'l' => array('l', 'L', 'l', 'L', '︱', '︳', '|'),
78
-			'm' => array('m', 'M', 'm', 'M', 'Μ', 'М', 'м'),
79
-			'n' => array('n', 'N', 'n', 'N', 'Ν', '∩'),
80
-			'o' => array('o', 'O', 'o', 'O', 'Ο', 'О'),
81
-			'p' => array('p', 'P', 'p', 'P', 'Ρ', 'Р', 'р'),
82
-			'q' => array('q', 'Q', 'q', 'Q'),
83
-			'r' => array('r', 'R', 'r', 'R'),
84
-			's' => array('s', 'S', 's', 'S'),
85
-			't' => array('t', 'T', 't', 'T', 'Τ', 'Т', 'ㄒ'),
86
-			'u' => array('u', 'U', 'u', 'U', '∪'),
87
-			'v' => array('v', 'V', 'v', 'V', '∨', 'ν'),
88
-			'w' => array('w', 'W', 'w', 'W'),
89
-			'x' => array('x', 'X', 'x', 'X', 'Χ', 'χ', 'Х', 'х', 'Ⅹ', '×'),
90
-			'y' => array('y', 'Y', 'y', 'Y', 'У'),
91
-			'z' => array('z', 'Z', 'z', 'Z', 'Ζ'),
60
+    /**
61
+     * @param string $url
62
+     */
63
+    function setChacha($url) {
64
+        $url=strtolower($url);
65
+        $arr=array(
66
+            'a' => array('a', 'A', 'a', 'A', 'Α', 'А', 'α'),
67
+            'b' => array('b', 'B', 'b', 'B', 'Β', 'В', 'Ь'),
68
+            'c' => array('c', 'C', 'c', 'C', 'С', 'с'),
69
+            'd' => array('d', 'D', 'd', 'D'),
70
+            'e' => array('e', 'E', 'e', 'E', 'Ε', 'Е', 'е'),
71
+            'f' => array('f', 'F', 'f', 'F'),
72
+            'g' => array('g', 'G', 'g', 'G'),
73
+            'h' => array('h', 'H', 'h', 'H', 'Η', 'Н', 'н'),
74
+            'i' => array('i', 'I', 'i', 'I', 'Ι', 'Ⅰ'),
75
+            'j' => array('j', 'J', 'j', 'J'),
76
+            'k' => array('k', 'K', 'k', 'K', 'Κ', 'κ', 'к', 'К'),
77
+            'l' => array('l', 'L', 'l', 'L', '︱', '︳', '|'),
78
+            'm' => array('m', 'M', 'm', 'M', 'Μ', 'М', 'м'),
79
+            'n' => array('n', 'N', 'n', 'N', 'Ν', '∩'),
80
+            'o' => array('o', 'O', 'o', 'O', 'Ο', 'О'),
81
+            'p' => array('p', 'P', 'p', 'P', 'Ρ', 'Р', 'р'),
82
+            'q' => array('q', 'Q', 'q', 'Q'),
83
+            'r' => array('r', 'R', 'r', 'R'),
84
+            's' => array('s', 'S', 's', 'S'),
85
+            't' => array('t', 'T', 't', 'T', 'Τ', 'Т', 'ㄒ'),
86
+            'u' => array('u', 'U', 'u', 'U', '∪'),
87
+            'v' => array('v', 'V', 'v', 'V', '∨', 'ν'),
88
+            'w' => array('w', 'W', 'w', 'W'),
89
+            'x' => array('x', 'X', 'x', 'X', 'Χ', 'χ', 'Х', 'х', 'Ⅹ', '×'),
90
+            'y' => array('y', 'Y', 'y', 'Y', 'У'),
91
+            'z' => array('z', 'Z', 'z', 'Z', 'Ζ'),
92 92
 			
93
-			'1' => array('1', '1'),
94
-			'2' => array('2', '2'),
95
-			'3' => array('3', '3'),
96
-			'4' => array('4', '4'),
97
-			'5' => array('5', '5'),
98
-			'6' => array('6', '6'),
99
-			'7' => array('7', '7'),
100
-			'8' => array('8', '8'),
101
-			'9' => array('9', '9'),
102
-			'0' => array('0', '0'),
93
+            '1' => array('1', '1'),
94
+            '2' => array('2', '2'),
95
+            '3' => array('3', '3'),
96
+            '4' => array('4', '4'),
97
+            '5' => array('5', '5'),
98
+            '6' => array('6', '6'),
99
+            '7' => array('7', '7'),
100
+            '8' => array('8', '8'),
101
+            '9' => array('9', '9'),
102
+            '0' => array('0', '0'),
103 103
 			
104
-			':' => array(':', ':', '∶'),
105
-			'/' => array('/', '/'),
106
-			'.' => array('。', '·', '.', '、', '﹒', ',', '丶')
104
+            ':' => array(':', ':', '∶'),
105
+            '/' => array('/', '/'),
106
+            '.' => array('。', '·', '.', '、', '﹒', ',', '丶')
107 107
 		
108
-		);
109
-		$len=strlen($url);
110
-		$temp="\n\n";
111
-		for ($i=0; $i < $len; $i++) {
112
-			$t_str=substr($url, $i, 1);
113
-			$sj=mt_rand(0, count($arr[$t_str]) - 1);
114
-			$temp.=$arr[$t_str][$sj];
115
-		}
116
-		return $temp;
117
-	}
108
+        );
109
+        $len=strlen($url);
110
+        $temp="\n\n";
111
+        for ($i=0; $i < $len; $i++) {
112
+            $t_str=substr($url, $i, 1);
113
+            $sj=mt_rand(0, count($arr[$t_str]) - 1);
114
+            $temp.=$arr[$t_str][$sj];
115
+        }
116
+        return $temp;
117
+    }
118 118
 
119
-	//随机把一个字符转为拼音
119
+    //随机把一个字符转为拼音
120 120
 
121
-	/**
122
-	 * @param string $str
123
-	 */
124
-	function setPinyin($str) {
125
-		$py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
126
-		$t_str = iconv_substr( $str, $py, 1, 'UTF-8');
127
-		if(mt_rand(0,10) > 5) {
128
-		    $pinyin = " ";
129
-		}
130
-		$pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE);
121
+    /**
122
+     * @param string $str
123
+     */
124
+    function setPinyin($str) {
125
+        $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1);
126
+        $t_str = iconv_substr( $str, $py, 1, 'UTF-8');
127
+        if(mt_rand(0,10) > 5) {
128
+            $pinyin = " ";
129
+        }
130
+        $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE);
131 131
         $pinyin=implode(" ",$pinyin);
132
-		if(mt_rand(0,10) > 5) {
133
-		    $pinyin .= " ";
134
-		}
135
-		if($t_str != "%"){
136
-			$str = preg_replace("'$t_str'", $pinyin, $str, 1);
137
-		}
138
-		return $str;
139
-	}
132
+        if(mt_rand(0,10) > 5) {
133
+            $pinyin .= " ";
134
+        }
135
+        if($t_str != "%"){
136
+            $str = preg_replace("'$t_str'", $pinyin, $str, 1);
137
+        }
138
+        return $str;
139
+    }
140 140
 	
141
-	//随机重复一个字符
141
+    //随机重复一个字符
142 142
 
143
-	/**
144
-	 * @param string $str
145
-	 */
146
-	function setRepeat($str) {
147
-		$len = iconv_strlen( $str, 'UTF-8' );
148
-		$action = 0;
149
-		$temp = '';
150
-		for( $i=0;  $i<$len; $i++ ){
151
-			$t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
152
-			if( mt_rand( 1, 50 ) > 48 && $action == 0) {
153
-				if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
154
-					$temp .= $t_str;
155
-					$action = 1;
156
-				}
157
-			}
158
-			$temp .= $t_str;
159
-		}
160
-		return $temp;
161
-	}
143
+    /**
144
+     * @param string $str
145
+     */
146
+    function setRepeat($str) {
147
+        $len = iconv_strlen( $str, 'UTF-8' );
148
+        $action = 0;
149
+        $temp = '';
150
+        for( $i=0;  $i<$len; $i++ ){
151
+            $t_str = iconv_substr( $str, $i, 1 ,'UTF-8');
152
+            if( mt_rand( 1, 50 ) > 48 && $action == 0) {
153
+                if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
154
+                    $temp .= $t_str;
155
+                    $action = 1;
156
+                }
157
+            }
158
+            $temp .= $t_str;
159
+        }
160
+        return $temp;
161
+    }
162 162
 	
163
-	//随机插入不影响阅读的字符
163
+    //随机插入不影响阅读的字符
164 164
 
165
-	/**
166
-	 * @param string $str
167
-	 */
168
-	function setBlankness($str) {
169
-		$blankness=array(" ", ' ', '҉', '̅̅', '̲', '̲̲', '̅', '̲̲̅̅');
170
-		$len=iconv_strlen($str, 'UTF-8');
171
-		$temp='';
172
-		for ($i=0; $i < $len; $i++) {
173
-			$t_str=iconv_substr($str, $i, 1, 'UTF-8');
174
-			if (mt_rand(1, 50) > 48) {
175
-				if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
176
-					$temp.=$blankness[mt_rand(0, 7)];
177
-				}
178
-			}
179
-			$temp.=$t_str;
180
-		}
181
-		return $temp;
182
-	}
165
+    /**
166
+     * @param string $str
167
+     */
168
+    function setBlankness($str) {
169
+        $blankness=array(" ", ' ', '҉', '̅̅', '̲', '̲̲', '̅', '̲̲̅̅');
170
+        $len=iconv_strlen($str, 'UTF-8');
171
+        $temp='';
172
+        for ($i=0; $i < $len; $i++) {
173
+            $t_str=iconv_substr($str, $i, 1, 'UTF-8');
174
+            if (mt_rand(1, 50) > 48) {
175
+                if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) {
176
+                    $temp.=$blankness[mt_rand(0, 7)];
177
+                }
178
+            }
179
+            $temp.=$t_str;
180
+        }
181
+        return $temp;
182
+    }
183 183
 	
184
-	//随机进行繁体中文转换
185
-	function GbToBig($str) {
186
-		$len=iconv_strlen($str, 'UTF-8');
187
-		$temp='';
188
-		for ($i=0; $i < $len; $i++) {
189
-			$t_str=iconv_substr($str, $i, 1, 'UTF-8');
190
-			if (mt_rand(1, 50) > 48) {
191
-				$t_str=strtr($t_str, $this->GbToBigArray);
192
-			}
193
-			$temp.=$t_str;
194
-		}
195
-		return $temp;
196
-	}
184
+    //随机进行繁体中文转换
185
+    function GbToBig($str) {
186
+        $len=iconv_strlen($str, 'UTF-8');
187
+        $temp='';
188
+        for ($i=0; $i < $len; $i++) {
189
+            $t_str=iconv_substr($str, $i, 1, 'UTF-8');
190
+            if (mt_rand(1, 50) > 48) {
191
+                $t_str=strtr($t_str, $this->GbToBigArray);
192
+            }
193
+            $temp.=$t_str;
194
+        }
195
+        return $temp;
196
+    }
197 197
 }
198 198
 
199 199
 
Please login to merge, or discard this patch.
core/Route.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -98,8 +98,7 @@
 block discarded – undo
98 98
             }
99 99
         } catch (\ReflectionException $e) {
100 100
             return false;
101
-        }
102
-        catch (\InvalidArgumentException $e) {
101
+        } catch (\InvalidArgumentException $e) {
103 102
             return false;
104 103
         }
105 104
         return true;
Please login to merge, or discard this patch.
core/Mysql.php 1 patch
Braces   +27 added lines, -20 removed lines patch added patch discarded remove patch
@@ -268,8 +268,9 @@  discard block
 block discarded – undo
268 268
      * @return void
269 269
      */
270 270
     public function disconnect() {
271
-        if (!$this->_mysqli)
272
-            return;
271
+        if (!$this->_mysqli) {
272
+                    return;
273
+        }
273 274
         $this->_mysqli->close();
274 275
         $this->_mysqli = null;
275 276
     }
@@ -556,8 +557,9 @@  discard block
 block discarded – undo
556 557
 
557 558
         // if $meta is false yet sqlstate is true, there's no sql error but the query is
558 559
         // most likely an update/insert/delete which doesn't produce any results
559
-        if (!$meta && $stmt->sqlstate)
560
-            return array();
560
+        if (!$meta && $stmt->sqlstate) {
561
+                    return array();
562
+        }
561 563
 
562 564
         $row = array();
563 565
         while ($field = $meta->fetch_field()) {
@@ -743,16 +745,18 @@  discard block
 block discarded – undo
743 745
      * Abstraction method that will build an JOIN part of the query
744 746
      */
745 747
     protected function _buildJoin() {
746
-        if (empty ($this->_join))
747
-            return;
748
+        if (empty ($this->_join)) {
749
+                    return;
750
+        }
748 751
 
749 752
         foreach ($this->_join as $data) {
750 753
             list ($joinType, $joinTable, $joinCondition) = $data;
751 754
 
752
-            if (is_object($joinTable))
753
-                $joinStr = $this->_buildPair("", $joinTable);
754
-            else
755
-                $joinStr = $joinTable;
755
+            if (is_object($joinTable)) {
756
+                            $joinStr = $this->_buildPair("", $joinTable);
757
+            } else {
758
+                            $joinStr = $joinTable;
759
+            }
756 760
 
757 761
             $this->_query .= " " . $joinType . " JOIN " . $joinStr . " on " . $joinCondition;
758 762
 
@@ -840,12 +844,13 @@  discard block
 block discarded – undo
840 844
                 $this->_query .= $operator . $this->_buildPair("", $val);
841 845
                 break;
842 846
             default:
843
-                if (is_array($val))
844
-                    $this->_bindParams($val);
845
-                else if ($val === null)
846
-                    $this->_query .= $operator . " NULL";
847
-                else if ($val != 'DBNULL' || $val == '0')
848
-                    $this->_query .= $this->_buildPair($operator, $val);
847
+                if (is_array($val)) {
848
+                                    $this->_bindParams($val);
849
+                } else if ($val === null) {
850
+                                    $this->_query .= $operator . " NULL";
851
+                } else if ($val != 'DBNULL' || $val == '0') {
852
+                                    $this->_query .= $this->_buildPair($operator, $val);
853
+                }
849 854
         }
850 855
     }
851 856
 
@@ -862,8 +867,9 @@  discard block
 block discarded – undo
862 867
         $isInsert = preg_match('/^[INSERT|REPLACE]/', $this->_query);
863 868
         $dataColumns = array_keys($tableData);
864 869
         if ($isInsert) {
865
-            if (isset ($dataColumns[0]))
866
-                $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) ';
870
+            if (isset ($dataColumns[0])) {
871
+                            $this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) ';
872
+            }
867 873
             $this->_query .= ' VALUES (';
868 874
         } else {
869 875
             $this->_query .= " SET ";
@@ -2038,8 +2044,9 @@  discard block
 block discarded – undo
2038 2044
             return false;
2039 2045
         }
2040 2046
 
2041
-        foreach ($tables as $i => $value)
2042
-            $tables[$i] = $this->prefix . $value;
2047
+        foreach ($tables as $i => $value) {
2048
+                    $tables[$i] = $this->prefix . $value;
2049
+        }
2043 2050
         $this->where('table_schema', $this->db);
2044 2051
         $this->where('table_name', $tables, 'in');
2045 2052
         $this->get('information_schema.tables', $count);
Please login to merge, or discard this patch.
core/App.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,8 +34,7 @@
 block discarded – undo
34 34
         try{
35 35
             $dotEnv = new Dotenv($this->basePath);
36 36
             $dotEnv->load();
37
-        }
38
-        catch (\Dotenv\Exception\InvalidPathException $e){
37
+        } catch (\Dotenv\Exception\InvalidPathException $e){
39 38
 
40 39
         }
41 40
         date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai'));
Please login to merge, or discard this patch.
core/Model.php 1 patch
Braces   +183 added lines, -125 removed lines patch added patch discarded remove patch
@@ -101,8 +101,9 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public static function table($tableName) {
103 103
         $tableName = preg_replace("/[^-a-z0-9_]+/i", '', $tableName);
104
-        if (!class_exists($tableName))
105
-            eval ("class $tableName extends dbObject {}");
104
+        if (!class_exists($tableName)) {
105
+                    eval ("class $tableName extends dbObject {}");
106
+        }
106 107
         return new $tableName ();
107 108
     }
108 109
 
@@ -119,23 +120,26 @@  discard block
 block discarded – undo
119 120
     public static function __callStatic($method, $arg) {
120 121
         $obj = new static;
121 122
         $result = call_user_func_array(array($obj, $method), $arg);
122
-        if (method_exists($obj, $method))
123
-            return $result;
123
+        if (method_exists($obj, $method)) {
124
+                    return $result;
125
+        }
124 126
         return $obj;
125 127
     }
126 128
 
127 129
     public static function autoload($path = null) {
128
-        if ($path)
129
-            static::$modelPath = $path . "/";
130
-        else
131
-            static::$modelPath = __DIR__ . "/models/";
130
+        if ($path) {
131
+                    static::$modelPath = $path . "/";
132
+        } else {
133
+                    static::$modelPath = __DIR__ . "/models/";
134
+        }
132 135
         spl_autoload_register("dbObject::dbObjectAutoload");
133 136
     }
134 137
 
135 138
     private static function dbObjectAutoload($classname) {
136 139
         $filename = static::$modelPath . $classname . ".php";
137
-        if (file_exists($filename))
138
-            include($filename);
140
+        if (file_exists($filename)) {
141
+                    include($filename);
142
+        }
139 143
     }
140 144
 
141 145
     /**
@@ -146,11 +150,13 @@  discard block
 block discarded – undo
146 150
      * @return mixed
147 151
      */
148 152
     public function __get($name) {
149
-        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false)
150
-            return null;
153
+        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) {
154
+                    return null;
155
+        }
151 156
 
152
-        if (isset ($this->data[$name]) && $this->data[$name] instanceof dbObject)
153
-            return $this->data[$name];
157
+        if (isset ($this->data[$name]) && $this->data[$name] instanceof dbObject) {
158
+                    return $this->data[$name];
159
+        }
154 160
 
155 161
         if (property_exists($this, 'relations') && isset ($this->relations[$name])) {
156 162
             $relationType = strtolower($this->relations[$name][0]);
@@ -173,11 +179,13 @@  discard block
 block discarded – undo
173 179
             }
174 180
         }
175 181
 
176
-        if (isset ($this->data[$name]))
177
-            return $this->data[$name];
182
+        if (isset ($this->data[$name])) {
183
+                    return $this->data[$name];
184
+        }
178 185
 
179
-        if (property_exists($this->db, $name))
180
-            return $this->db->$name;
186
+        if (property_exists($this->db, $name)) {
187
+                    return $this->db->$name;
188
+        }
181 189
     }
182 190
 
183 191
     /**
@@ -186,18 +194,21 @@  discard block
 block discarded – undo
186 194
      * @return mixed
187 195
      */
188 196
     public function __set($name, $value) {
189
-        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false)
190
-            return;
197
+        if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) {
198
+                    return;
199
+        }
191 200
 
192 201
         $this->data[$name] = $value;
193 202
     }
194 203
 
195 204
     public function __isset($name) {
196
-        if (isset ($this->data[$name]))
197
-            return isset ($this->data[$name]);
205
+        if (isset ($this->data[$name])) {
206
+                    return isset ($this->data[$name]);
207
+        }
198 208
 
199
-        if (property_exists($this->db, $name))
200
-            return isset ($this->db->$name);
209
+        if (property_exists($this->db, $name)) {
210
+                    return isset ($this->db->$name);
211
+        }
201 212
     }
202 213
 
203 214
     public function __unset($name) {
@@ -210,8 +221,9 @@  discard block
 block discarded – undo
210 221
      * @return mixed insert id or false in case of failure
211 222
      */
212 223
     public function save($data = null) {
213
-        if ($this->isNew)
214
-            return $this->insert();
224
+        if ($this->isNew) {
225
+                    return $this->insert();
226
+        }
215 227
         return $this->update($data);
216 228
     }
217 229
 
@@ -219,15 +231,18 @@  discard block
 block discarded – undo
219 231
      * @return mixed insert id or false in case of failure
220 232
      */
221 233
     public function insert() {
222
-        if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps))
223
-            $this->createdAt = date("Y-m-d H:i:s");
234
+        if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) {
235
+                    $this->createdAt = date("Y-m-d H:i:s");
236
+        }
224 237
         $sqlData = $this->prepareData();
225
-        if (!$this->validate($sqlData))
226
-            return false;
238
+        if (!$this->validate($sqlData)) {
239
+                    return false;
240
+        }
227 241
 
228 242
         $id = $this->db->insert($this->dbTable, $sqlData);
229
-        if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey]))
230
-            $this->data[$this->primaryKey] = $id;
243
+        if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey])) {
244
+                    $this->data[$this->primaryKey] = $id;
245
+        }
231 246
         $this->isNew = false;
232 247
 
233 248
         return $id;
@@ -236,38 +251,44 @@  discard block
 block discarded – undo
236 251
     private function prepareData() {
237 252
         $this->errors = Array();
238 253
         $sqlData = Array();
239
-        if (count($this->data) == 0)
240
-            return Array();
254
+        if (count($this->data) == 0) {
255
+                    return Array();
256
+        }
241 257
 
242
-        if (method_exists($this, "preLoad"))
243
-            $this->preLoad($this->data);
258
+        if (method_exists($this, "preLoad")) {
259
+                    $this->preLoad($this->data);
260
+        }
244 261
 
245
-        if (!$this->dbFields)
246
-            return $this->data;
262
+        if (!$this->dbFields) {
263
+                    return $this->data;
264
+        }
247 265
 
248 266
         foreach ($this->data as $key => &$value) {
249 267
             if ($value instanceof dbObject && $value->isNew == true) {
250 268
                 $id = $value->save();
251
-                if ($id)
252
-                    $value = $id;
253
-                else
254
-                    $this->errors = array_merge($this->errors, $value->errors);
269
+                if ($id) {
270
+                                    $value = $id;
271
+                } else {
272
+                                    $this->errors = array_merge($this->errors, $value->errors);
273
+                }
255 274
             }
256 275
 
257
-            if (!in_array($key, array_keys($this->dbFields)))
258
-                continue;
276
+            if (!in_array($key, array_keys($this->dbFields))) {
277
+                            continue;
278
+            }
259 279
 
260 280
             if (!is_array($value)) {
261 281
                 $sqlData[$key] = $value;
262 282
                 continue;
263 283
             }
264 284
 
265
-            if (isset ($this->jsonFields) && in_array($key, $this->jsonFields))
266
-                $sqlData[$key] = json_encode($value);
267
-            else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields))
268
-                $sqlData[$key] = implode("|", $value);
269
-            else
270
-                $sqlData[$key] = $value;
285
+            if (isset ($this->jsonFields) && in_array($key, $this->jsonFields)) {
286
+                            $sqlData[$key] = json_encode($value);
287
+            } else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields)) {
288
+                            $sqlData[$key] = implode("|", $value);
289
+            } else {
290
+                            $sqlData[$key] = $value;
291
+            }
271 292
         }
272 293
         return $sqlData;
273 294
     }
@@ -276,31 +297,37 @@  discard block
 block discarded – undo
276 297
      * @param array $data
277 298
      */
278 299
     private function validate($data) {
279
-        if (!$this->dbFields)
280
-            return true;
300
+        if (!$this->dbFields) {
301
+                    return true;
302
+        }
281 303
 
282 304
         foreach ($this->dbFields as $key => $desc) {
283 305
             $type = null;
284 306
             $required = false;
285
-            if (isset ($data[$key]))
286
-                $value = $data[$key];
287
-            else
288
-                $value = null;
307
+            if (isset ($data[$key])) {
308
+                            $value = $data[$key];
309
+            } else {
310
+                            $value = null;
311
+            }
289 312
 
290
-            if (is_array($value))
291
-                continue;
313
+            if (is_array($value)) {
314
+                            continue;
315
+            }
292 316
 
293
-            if (isset ($desc[0]))
294
-                $type = $desc[0];
295
-            if (isset ($desc[1]) && ($desc[1] == 'required'))
296
-                $required = true;
317
+            if (isset ($desc[0])) {
318
+                            $type = $desc[0];
319
+            }
320
+            if (isset ($desc[1]) && ($desc[1] == 'required')) {
321
+                            $required = true;
322
+            }
297 323
 
298 324
             if ($required && strlen($value) == 0) {
299 325
                 $this->errors[] = Array($this->dbTable . "." . $key => "is required");
300 326
                 continue;
301 327
             }
302
-            if ($value == null)
303
-                continue;
328
+            if ($value == null) {
329
+                            continue;
330
+            }
304 331
 
305 332
             switch ($type) {
306 333
                 case "text";
@@ -322,8 +349,9 @@  discard block
 block discarded – undo
322 349
                     $regexp = $type;
323 350
                     break;
324 351
             }
325
-            if (!$regexp)
326
-                continue;
352
+            if (!$regexp) {
353
+                            continue;
354
+            }
327 355
 
328 356
             if (!preg_match($regexp, $value)) {
329 357
                 $this->errors[] = Array($this->dbTable . "." . $key => "$type validation failed");
@@ -337,23 +365,28 @@  discard block
 block discarded – undo
337 365
      * @param array $data Optional update data to apply to the object
338 366
      */
339 367
     public function update($data = null) {
340
-        if (empty ($this->dbFields))
341
-            return false;
368
+        if (empty ($this->dbFields)) {
369
+                    return false;
370
+        }
342 371
 
343
-        if (empty ($this->data[$this->primaryKey]))
344
-            return false;
372
+        if (empty ($this->data[$this->primaryKey])) {
373
+                    return false;
374
+        }
345 375
 
346 376
         if ($data) {
347
-            foreach ($data as $k => $v)
348
-                $this->$k = $v;
377
+            foreach ($data as $k => $v) {
378
+                            $this->$k = $v;
379
+            }
349 380
         }
350 381
 
351
-        if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps))
352
-            $this->updatedAt = date("Y-m-d H:i:s");
382
+        if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps)) {
383
+                    $this->updatedAt = date("Y-m-d H:i:s");
384
+        }
353 385
 
354 386
         $sqlData = $this->prepareData();
355
-        if (!$this->validate($sqlData))
356
-            return false;
387
+        if (!$this->validate($sqlData)) {
388
+                    return false;
389
+        }
357 390
 
358 391
         $this->db->where($this->primaryKey, $this->data[$this->primaryKey]);
359 392
         return $this->db->update($this->dbTable, $sqlData);
@@ -365,8 +398,9 @@  discard block
 block discarded – undo
365 398
      * @return boolean Indicates success. 0 or 1.
366 399
      */
367 400
     public function delete() {
368
-        if (empty ($this->data[$this->primaryKey]))
369
-            return false;
401
+        if (empty ($this->data[$this->primaryKey])) {
402
+                    return false;
403
+        }
370 404
 
371 405
         $this->db->where($this->primaryKey, $this->data[$this->primaryKey]);
372 406
         return $this->db->delete($this->dbTable);
@@ -381,8 +415,9 @@  discard block
 block discarded – undo
381 415
      * @return mixed
382 416
      */
383 417
     public function __call($method, $arg) {
384
-        if (method_exists($this, $method))
385
-            return call_user_func_array(array($this, $method), $arg);
418
+        if (method_exists($this, $method)) {
419
+                    return call_user_func_array(array($this, $method), $arg);
420
+        }
386 421
         $this->db->table($this->dbTable);
387 422
         return call_user_func_array(array($this->db, $method), $arg);;
388 423
     }
@@ -414,8 +449,9 @@  discard block
 block discarded – undo
414 449
         $data = $this->data;
415 450
         $this->processAllWith($data);
416 451
         foreach ($data as &$d) {
417
-            if ($d instanceof dbObject)
418
-                $d = $d->data;
452
+            if ($d instanceof dbObject) {
453
+                            $d = $d->data;
454
+            }
419 455
         }
420 456
         return $data;
421 457
     }
@@ -426,8 +462,9 @@  discard block
 block discarded – undo
426 462
      * @param array $data
427 463
      */
428 464
     private function processAllWith(&$data, $shouldReset = true) {
429
-        if (count($this->_with) == 0)
430
-            return;
465
+        if (count($this->_with) == 0) {
466
+                    return;
467
+        }
431 468
 
432 469
         foreach ($this->_with as $name => $opts) {
433 470
             $relationType = strtolower($opts[0]);
@@ -454,11 +491,13 @@  discard block
 block discarded – undo
454 491
                     }
455 492
                 }
456 493
                 unset ($data[$table]);
457
-            } else
458
-                $data[$name] = $this->$name;
494
+            } else {
495
+                            $data[$name] = $this->$name;
496
+            }
497
+        }
498
+        if ($shouldReset) {
499
+                    $this->_with = Array();
459 500
         }
460
-        if ($shouldReset)
461
-            $this->_with = Array();
462 501
     }
463 502
 
464 503
     /**
@@ -475,8 +514,9 @@  discard block
 block discarded – undo
475 514
         $objects = Array();
476 515
         $this->processHasOneWith();
477 516
         $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields);
478
-        if ($this->db->count == 0)
479
-            return null;
517
+        if ($this->db->count == 0) {
518
+                    return null;
519
+        }
480 520
 
481 521
         foreach ($results as &$r) {
482 522
             $this->processArrays($r);
@@ -489,24 +529,28 @@  discard block
 block discarded – undo
489 529
             }
490 530
         }
491 531
         $this->_with = Array();
492
-        if ($this->returnType == 'Object')
493
-            return $objects;
532
+        if ($this->returnType == 'Object') {
533
+                    return $objects;
534
+        }
494 535
 
495
-        if ($this->returnType == 'Json')
496
-            return json_encode($results);
536
+        if ($this->returnType == 'Json') {
537
+                    return json_encode($results);
538
+        }
497 539
 
498 540
         return $results;
499 541
     }
500 542
 
501 543
     private function processHasOneWith() {
502
-        if (count($this->_with) == 0)
503
-            return;
544
+        if (count($this->_with) == 0) {
545
+                    return;
546
+        }
504 547
         foreach ($this->_with as $name => $opts) {
505 548
             $relationType = strtolower($opts[0]);
506 549
             $modelName = $opts[1];
507 550
             $key = null;
508
-            if (isset ($opts[2]))
509
-                $key = $opts[2];
551
+            if (isset ($opts[2])) {
552
+                            $key = $opts[2];
553
+            }
510 554
             if ($relationType == 'hasone') {
511 555
                 $this->db->setQueryOption("MYSQLI_NESTJOIN");
512 556
                 $this->join($modelName, $key);
@@ -527,16 +571,19 @@  discard block
 block discarded – undo
527 571
      */
528 572
     private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) {
529 573
         $joinObj = new $objectName;
530
-        if (!$key)
531
-            $key = $objectName . "id";
574
+        if (!$key) {
575
+                    $key = $objectName . "id";
576
+        }
532 577
 
533
-        if (!$primaryKey)
534
-            $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
578
+        if (!$primaryKey) {
579
+                    $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey;
580
+        }
535 581
 
536
-        if (!strchr($key, '.'))
537
-            $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
538
-        else
539
-            $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
582
+        if (!strchr($key, '.')) {
583
+                    $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey;
584
+        } else {
585
+                    $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey;
586
+        }
540 587
 
541 588
         $this->db->join($joinObj->dbTable, $joinStr, $joinType);
542 589
         return $this;
@@ -547,13 +594,15 @@  discard block
 block discarded – undo
547 594
      */
548 595
     private function processArrays(&$data) {
549 596
         if (isset ($this->jsonFields) && is_array($this->jsonFields)) {
550
-            foreach ($this->jsonFields as $key)
551
-                $data[$key] = json_decode($data[$key]);
597
+            foreach ($this->jsonFields as $key) {
598
+                            $data[$key] = json_decode($data[$key]);
599
+            }
552 600
         }
553 601
 
554 602
         if (isset ($this->arrayFields) && is_array($this->arrayFields)) {
555
-            foreach ($this->arrayFields as $key)
556
-                $data[$key] = explode("|", $data[$key]);
603
+            foreach ($this->arrayFields as $key) {
604
+                            $data[$key] = explode("|", $data[$key]);
605
+            }
557 606
         }
558 607
     }
559 608
 
@@ -564,8 +613,9 @@  discard block
 block discarded – undo
564 613
      */
565 614
     protected function count() {
566 615
         $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)");
567
-        if (!$res)
568
-            return 0;
616
+        if (!$res) {
617
+                    return 0;
618
+        }
569 619
         return $res;
570 620
     }
571 621
 
@@ -629,16 +679,19 @@  discard block
 block discarded – undo
629 679
     protected function getOne($fields = null) {
630 680
         $this->processHasOneWith();
631 681
         $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields);
632
-        if ($this->db->count == 0)
633
-            return null;
682
+        if ($this->db->count == 0) {
683
+                    return null;
684
+        }
634 685
 
635 686
         $this->processArrays($results);
636 687
         $this->data = $results;
637 688
         $this->processAllWith($results);
638
-        if ($this->returnType == 'Json')
639
-            return json_encode($results);
640
-        if ($this->returnType == 'Array')
641
-            return $results;
689
+        if ($this->returnType == 'Json') {
690
+                    return json_encode($results);
691
+        }
692
+        if ($this->returnType == 'Array') {
693
+                    return $results;
694
+        }
642 695
 
643 696
         $item = new static ($results);
644 697
         $item->isNew = false;
@@ -655,8 +708,9 @@  discard block
 block discarded – undo
655 708
      * @return dbObject
656 709
      */
657 710
     private function with($objectName) {
658
-        if (!property_exists($this, 'relations') && !isset ($this->relations[$name]))
659
-            die ("No relation with name $objectName found");
711
+        if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) {
712
+                    die ("No relation with name $objectName found");
713
+        }
660 714
 
661 715
         $this->_with[$objectName] = $this->relations[$objectName];
662 716
 
@@ -683,7 +737,9 @@  discard block
 block discarded – undo
683 737
         $this->db->pageLimit = self::$pageLimit;
684 738
         $res = $this->db->paginate($this->dbTable, $page, $fields);
685 739
         self::$totalPages = $this->db->totalPages;
686
-        if ($this->db->count == 0) return null;
740
+        if ($this->db->count == 0) {
741
+            return null;
742
+        }
687 743
 
688 744
         foreach ($res as &$r) {
689 745
             $this->processArrays($r);
@@ -696,11 +752,13 @@  discard block
 block discarded – undo
696 752
             }
697 753
         }
698 754
         $this->_with = Array();
699
-        if ($this->returnType == 'Object')
700
-            return $objects;
755
+        if ($this->returnType == 'Object') {
756
+                    return $objects;
757
+        }
701 758
 
702
-        if ($this->returnType == 'Json')
703
-            return json_encode($res);
759
+        if ($this->returnType == 'Json') {
760
+                    return json_encode($res);
761
+        }
704 762
 
705 763
         return $res;
706 764
     }
Please login to merge, or discard this patch.
core/helpers/Dispatch.php 1 patch
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -109,10 +109,10 @@
 block discarded – undo
109 109
 
110 110
         if($renderType=='json'){
111 111
             $response=json($res);
112
-        }elseif ($renderType=='xml'){
112
+        } elseif ($renderType=='xml'){
113 113
             //todo:: 支持xml格式化输出
114 114
             $response='don\'t support xml now!';
115
-        }elseif ($renderType==""){
115
+        } elseif ($renderType==""){
116 116
             if(is_array($res)||is_object($res)){
117 117
                 $response=json($res);
118 118
             }
Please login to merge, or discard this patch.