Completed
Push — develop ( 5d2b16...3044c5 )
by Simon
19:15
created
src/GenericFilter.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * Remove all existing criteria from the filter.
62 62
 	 * @return self
63 63
 	 */
64
-	public function clear( $what = [] ) {
64
+	public function clear($what = []) {
65 65
 
66 66
 		$defaults = [
67 67
 			'criteria'  => [],
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 
73 73
 		$what = (array) $what;
74 74
 
75
-		if( empty($what) )
75
+		if (empty($what))
76 76
 			$what = array_keys($defaults);
77 77
 
78
-		foreach( $what as $k ) {
78
+		foreach ($what as $k) {
79 79
 			$this->$k = $defaults[$k];
80 80
 		}
81 81
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @param  string   $value
90 90
 	 * @return self
91 91
 	 */
92
-	public function equals( $field, $value ) {
92
+	public function equals($field, $value) {
93 93
 		return $this->addCriteria($field, '=', $value);
94 94
 	}
95 95
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @param  string   $value
100 100
 	 * @return self
101 101
 	 */
102
-	public function notEquals( $field, $value ) {
102
+	public function notEquals($field, $value) {
103 103
 		return $this->addCriteria($field, '!=', $value);
104 104
 	}
105 105
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @param  string   $value
110 110
 	 * @return self
111 111
 	 */
112
-	public function lessThan( $field, $value ) {
112
+	public function lessThan($field, $value) {
113 113
 		return $this->addCriteria($field, '<', $value);
114 114
 	}
115 115
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param  string   $value
120 120
 	 * @return self
121 121
 	 */
122
-	public function greaterThan( $field, $value ) {
122
+	public function greaterThan($field, $value) {
123 123
 		return $this->addCriteria($field, '>', $value);
124 124
 	}
125 125
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @param  string   $value
130 130
 	 * @return self
131 131
 	 */
132
-	public function equalsLessThan( $field, $value ) {
132
+	public function equalsLessThan($field, $value) {
133 133
 		return $this->addCriteria($field, '<=', $value);
134 134
 	}
135 135
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 * @param  string   $value
140 140
 	 * @return self
141 141
 	 */
142
-	public function equalsGreaterThan( $field, $value ) {
142
+	public function equalsGreaterThan($field, $value) {
143 143
 		return $this->addCriteria($field, '>=', $value);
144 144
 	}
145 145
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 * @param  string   $value   pattern to match
150 150
 	 * @return self
151 151
 	 */
152
-	public function like( $field, $value ) {
152
+	public function like($field, $value) {
153 153
 		return $this->addCriteria($field, 'LIKE', $value);
154 154
 	}
155 155
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param  string   $value   pattern to match
160 160
 	 * @return self
161 161
 	 */
162
-	public function notLike( $field, $value ) {
162
+	public function notLike($field, $value) {
163 163
 		return $this->addCriteria($field, 'NOT LIKE', $value);
164 164
 	}
165 165
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @param  array          $values    values to match
170 170
 	 * @return self
171 171
 	 */
172
-	public function in( $field, array $values ) {
172
+	public function in($field, array $values) {
173 173
 		return $this->addCriteria($field, 'IN', $values);
174 174
 	}
175 175
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @param  array          $values    values to exclude
180 180
 	 * @return self
181 181
 	 */
182
-	public function notIn( $field, array $values ) {
182
+	public function notIn($field, array $values) {
183 183
 		return $this->addCriteria($field, 'NOT IN', $values);
184 184
 	}
185 185
 
@@ -190,16 +190,16 @@  discard block
 block discarded – undo
190 190
 	 * @param  boolean  $dir     true to sort ascending, false to sort descending
191 191
 	 * @return self
192 192
 	 */
193
-	public function orderBy( $field, $dir = Filter::SORT_ASC ) {
193
+	public function orderBy($field, $dir = Filter::SORT_ASC) {
194 194
 	
195 195
 		$field = trim($field);
196 196
 
197
-		if( empty($field) )
197
+		if (empty($field))
198 198
 			throw new \InvalidArgumentException('No field specified');
199 199
 
200 200
 		$modifier = substr($field, 0, 1);
201 201
 
202
-		if( in_array($modifier, ['+', '-']) ) {
202
+		if (in_array($modifier, ['+', '-'])) {
203 203
 			$dir = ($modifier == '+');
204 204
 			$field = substr($field, 1);
205 205
 		}
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 * @param  integer  $offset
216 216
 	 * @return self
217 217
 	 */
218
-	public function offset( $offset ) {
218
+	public function offset($offset) {
219 219
 		$this->offset = max(0, (int) $offset);
220 220
 		return $this;
221 221
 	}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @param  integer  $limit
226 226
 	 * @return self
227 227
 	 */
228
-	public function limit( $limit )	 {
228
+	public function limit($limit) {
229 229
 		$this->limit = max(1, (int) $limit);
230 230
 		return $this;
231 231
 	}
@@ -236,47 +236,47 @@  discard block
 block discarded – undo
236 236
 	 * @param  array  $columns a map of field names to database column names
237 237
 	 * @return Query
238 238
 	 */
239
-	public function toQuery( Query $query, array $columns = [], $alias = '' ) {
239
+	public function toQuery(Query $query, array $columns = [], $alias = '') {
240 240
 
241
-		foreach( $this->criteria as $column => $criteria ) {
241
+		foreach ($this->criteria as $column => $criteria) {
242 242
 
243
-			if( !$column = $this->getColumnName($columns, $column, $alias) )
243
+			if (!$column = $this->getColumnName($columns, $column, $alias))
244 244
 				continue;
245 245
 
246
-			foreach( $criteria as $operator => $value ) {
246
+			foreach ($criteria as $operator => $value) {
247 247
 				$query->where($column, $operator, $value);
248 248
 			}
249 249
 
250 250
 		}
251 251
 
252
-		foreach( $this->getOrder() as $column => $ascending ) {
252
+		foreach ($this->getOrder() as $column => $ascending) {
253 253
 			$column = $this->getColumnName($columns, $column, $alias);
254
-			if( !$column )
254
+			if (!$column)
255 255
 				continue;
256 256
 			$query->orderBy($column, $ascending);
257 257
 		}
258 258
 
259
-		if( $this->offset )
259
+		if ($this->offset)
260 260
 			$query->offset($this->offset);
261 261
 
262
-		if( $this->limit )
262
+		if ($this->limit)
263 263
 			$query->limit($this->limit);
264 264
 
265 265
 		return $query;
266 266
 
267 267
 	}
268 268
 
269
-	protected function getColumnName( $columns, $column, $alias ) {
269
+	protected function getColumnName($columns, $column, $alias) {
270 270
 
271 271
 		$column = isset($columns[$column]) ? $columns[$column] : $column;
272 272
 
273
-		if( !$column )
273
+		if (!$column)
274 274
 			return '';
275 275
 
276
-		elseif( strpos($column, '.') )
276
+		elseif (strpos($column, '.'))
277 277
 			return $column;
278 278
 
279
-		elseif( $alias )
279
+		elseif ($alias)
280 280
 			return "{$alias}.{$column}";
281 281
 
282 282
 		return $column;
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 	 * @param  mixed    $value
291 291
 	 * @return self
292 292
 	 */
293
-	protected function addCriteria( $field, $operator, $value ) {
293
+	protected function addCriteria($field, $operator, $value) {
294 294
 
295 295
 		$field = trim($field);
296 296
 
297
-		if( !isset($this->criteria[$field]) )
297
+		if (!isset($this->criteria[$field]))
298 298
 			$this->criteria[$field] = [];
299 299
 
300 300
 		$this->criteria[$field][$operator] = $value;
Please login to merge, or discard this patch.
src/BaseConfig.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class BaseConfig extends collections\BaseDictionary implements Config {
35 35
 
36
-	public function load( $file, $key = '' ) {
36
+	public function load($file, $key = '') {
37 37
 
38 38
 		$config = [];
39 39
 
40 40
 		require $file;
41 41
 
42
-		if( !isset($config) || !is_array($config) )
42
+		if (!isset($config) || !is_array($config))
43 43
 			throw new \LogicException('Invalid Configuration');
44 44
 
45
-		if( empty($key)  )
45
+		if (empty($key))
46 46
 			$this->merge($config);
47 47
 		else
48 48
 			$this->set($key, $config);
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
 
52 52
 	}
53 53
 
54
-	public function has( $key ) {
54
+	public function has($key) {
55 55
 		return $this->get($key) !== null;
56 56
 	}
57 57
 
58
-	public function get( $key, $default = null ) {
58
+	public function get($key, $default = null) {
59 59
 		
60 60
 		$parts   = explode('.', $key);
61 61
 		$context = &$this->items;
62 62
 
63
-		foreach( $parts as $part ) {
64
-			if( !isset($context[$part]) ) {
63
+		foreach ($parts as $part) {
64
+			if (!isset($context[$part])) {
65 65
 				return $default;
66 66
 			}
67 67
 			$context = &$context[$part];
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
 
72 72
 	}
73 73
 
74
-	public function set( $key, $value ) {
74
+	public function set($key, $value) {
75 75
 
76 76
 		$parts   = explode('.', $key);
77 77
 		$count   = count($parts) - 1;
78 78
 		$context = &$this->items;
79 79
 
80
-		for( $i = 0; $i <= $count; $i++ ) {
80
+		for ($i = 0; $i <= $count; $i++) {
81 81
 			$part = $parts[$i];
82
-			if( !isset($context[$part]) && ($i < $count) ) {
82
+			if (!isset($context[$part]) && ($i < $count)) {
83 83
 				$context[$part] = [];
84 84
 			}
85
-			elseif( $i == $count ) {
85
+			elseif ($i == $count) {
86 86
 				$context[$part] = $value;
87
-				if( $parts[0] == 'php' ) {
87
+				if ($parts[0] == 'php') {
88 88
 					ini_set($part, $value);
89 89
 				}
90 90
 				return $this;
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 
97 97
 	}
98 98
 
99
-	public function merge( array $config ) {
99
+	public function merge(array $config) {
100 100
 
101
-		foreach( $config as $k => $v ) {
101
+		foreach ($config as $k => $v) {
102 102
 			$this->set($k, $v);
103 103
 		}
104 104
 
Please login to merge, or discard this patch.
src/Fieldset.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	 * @param  array    $rules   an array of validation rules
39 39
 	 * @return self
40 40
 	 */
41
-	public function add( $name, $type = Type::TEXT, $rules = [] ) {
41
+	public function add($name, $type = Type::TEXT, $rules = []) {
42 42
 		$this->fields[$name] = new Field($name, $type, $rules);
43
-		$this->types = [];	// clear this so it will be refreshed when we've finished adding fields
43
+		$this->types = []; // clear this so it will be refreshed when we've finished adding fields
44 44
 		return $this;
45 45
 	}
46 46
 
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
 	 * @param  array $data
50 50
 	 * @return array first element is an array of cleaned data, second is an array of the errors (if any)
51 51
 	 */
52
-	public function validate( array $data ) {
52
+	public function validate(array $data) {
53 53
 
54 54
 		$errors = [];
55 55
 
56
-		foreach( $this->fields as $field ) {
56
+		foreach ($this->fields as $field) {
57 57
 
58 58
 			$f = $field->name;
59 59
 			$v = isset($data[$f]) ? $data[$f] : null;
60 60
 
61 61
 			list($clean, $errors[$f]) = $field->validate($v);
62 62
 
63
-			if( !$errors[$f] )
63
+			if (!$errors[$f])
64 64
 				$data[$f] = $clean;
65 65
 
66 66
 		}
@@ -78,17 +78,17 @@  discard block
 block discarded – undo
78 78
 
79 79
 	public function getDefaults() {
80 80
 		$defaults = [];
81
-		foreach( $this->fields as $field ) {
81
+		foreach ($this->fields as $field) {
82 82
 			$defaults[$field->name] = $field->default;
83 83
 		}
84 84
 		return $defaults;
85 85
 	}
86 86
 
87
-	public function __get( $key ) {
87
+	public function __get($key) {
88 88
 		return isset($this->fields[$key]) ? $this->fields[$key] : null;
89 89
 	}
90 90
 
91
-	public function __isset( $key ) {
91
+	public function __isset($key) {
92 92
 		return isset($this->fields[$key]);
93 93
 	}
94 94
 
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 		return count($this->fields);
101 101
 	}
102 102
 
103
-	public function getByType( $type ) {
103
+	public function getByType($type) {
104 104
 
105 105
 		$type = strtolower($type);
106 106
 
107
-		if( !$this->types ) {
107
+		if (!$this->types) {
108 108
 			$this->types['unique'] = [];
109
-			foreach( $this->fields as $field ) {
109
+			foreach ($this->fields as $field) {
110 110
 
111
-				if( !isset($this->types[$field->type]) )
111
+				if (!isset($this->types[$field->type]))
112 112
 					$this->types[$field->type] = [];
113 113
 
114 114
 				$this->types[$field->type][] = $field->name;
115 115
 
116
-				if( $field->isUnique() )
116
+				if ($field->isUnique())
117 117
 					$this->types['unique'][] = $field->name;
118 118
 
119 119
 			}
Please login to merge, or discard this patch.
src/exceptions/ValidationException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 
16 16
 	protected $errors = [];
17 17
 
18
-	public function __construct( array $errors, $source, \Exception $previous = null ) {
18
+	public function __construct(array $errors, $source, \Exception $previous = null) {
19 19
 		parent::__construct("Validation Error: {$source}");
20 20
 		$this->errors = $errors;
21 21
 	}
Please login to merge, or discard this patch.
src/collections/BaseCollection.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
 	protected $items;
25 25
 
26
-	public function __construct( array $items = [] ) {
26
+	public function __construct(array $items = []) {
27 27
 		$this->items = $items;
28 28
 	}
29 29
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		return $this;
41 41
 	}
42 42
 
43
-	public function contains( $item ) {
43
+	public function contains($item) {
44 44
 		return array_search($item, $this->items) !== false;
45 45
 	}
46 46
 
Please login to merge, or discard this patch.
src/collections/BaseDictionary.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class BaseDictionary extends BaseCollection implements Dictionary {
20 20
 
21
-	public function has( $key ) {
21
+	public function has($key) {
22 22
 		return array_key_exists($key, $this->items);
23 23
 	}
24 24
 
25
-	public function get( $key, $default = null ) {
25
+	public function get($key, $default = null) {
26 26
 		return isset($this->items[$key]) ? $this->items[$key] : $default;
27 27
 	}
28 28
 
29
-	public function set( $key, $item ) {
29
+	public function set($key, $item) {
30 30
 
31 31
 		$current = $this->get($key);
32 32
 
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
 	}
38 38
 
39
-	public function remove( $key ) {
39
+	public function remove($key) {
40 40
 		$current = $this->get($key);
41 41
 		unset($this->items[$key]);
42 42
 		return $current;
Please login to merge, or discard this patch.
src/collections/BaseSet.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,21 +18,21 @@
 block discarded – undo
18 18
  */
19 19
 class BaseSet extends BaseCollection implements Set {
20 20
 
21
-	public function add( $item ) {
21
+	public function add($item) {
22 22
 
23 23
 		$new = !$this->contains($item);
24 24
 
25
-		if( $new )
25
+		if ($new)
26 26
 			$this->items[] = $item;
27 27
 
28 28
 		return $new;
29 29
 	}
30 30
 
31
-	public function remove( $item ) {
31
+	public function remove($item) {
32 32
 
33 33
 		$key = array_search($item, $this->items);
34 34
 
35
-		if( $key !== false )
35
+		if ($key !== false)
36 36
 			unset($this->items[$key]);
37 37
 
38 38
 		return $key !== false;
Please login to merge, or discard this patch.
src/Field.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 	protected $rules;
35 35
 
36
-	public function __construct( $name, $type = Type::TEXT, array $rules = [] ) {
36
+	public function __construct($name, $type = Type::TEXT, array $rules = []) {
37 37
 
38 38
 		$this->name = $name;
39 39
 		$this->type = $type;
@@ -51,18 +51,18 @@  discard block
 block discarded – undo
51 51
 
52 52
 	}
53 53
 
54
-	public function __get( $key ) {
55
-		if( $key == 'default' )
54
+	public function __get($key) {
55
+		if ($key == 'default')
56 56
 			return $this->getDefault();
57
-		elseif( isset($this->rules[$key]) )
57
+		elseif (isset($this->rules[$key]))
58 58
 			return $this->rules[$key];
59
-		elseif( isset($this->$key) )
59
+		elseif (isset($this->$key))
60 60
 			return $this->$key;
61 61
 		else
62 62
 			return null;
63 63
 	}
64 64
 
65
-	public function __isset( $key ) {
65
+	public function __isset($key) {
66 66
 		return isset($this->$key) || isset($this->rules[$key]);
67 67
 	}
68 68
 
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 		return !empty($this->rules['unique']);
127 127
 	}
128 128
 
129
-	public function cast( $v ) {
129
+	public function cast($v) {
130 130
 
131
-		switch( $this->type ) {
131
+		switch ($this->type) {
132 132
 			case Type::INTEGER:
133 133
 			case Type::TIMESTAMP:
134 134
 			case Type::YEAR:
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
 				return preg_match('/0000-00-00/', $v) ? '' : $v;
146 146
 
147 147
 			case Type::JSON:
148
-				if( !$v )
148
+				if (!$v)
149 149
 					$v = [];
150
-				elseif( !is_array($v) && is_array($arr = json_decode($v, true)) )
150
+				elseif (!is_array($v) && is_array($arr = json_decode($v, true)))
151 151
 					$v = $arr;
152 152
 				return $v;
153 153
 
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
 
158 158
 	}
159 159
 
160
-	public function validate( $v ) {
160
+	public function validate($v) {
161 161
 
162
-		if( $this->required && Validator::isEmpty($v, $this->type) )
162
+		if ($this->required && Validator::isEmpty($v, $this->type))
163 163
 			return [$v, Error::REQUIRED];
164 164
 
165
-		elseif( !$this->nullable && ($v === null) )
165
+		elseif (!$this->nullable && ($v === null))
166 166
 			return [$v, Error::NULL];
167 167
 
168 168
 		list($clean, $error) = $this->validateType($v, $this->type);
169 169
 
170
-		if( $error )
170
+		if ($error)
171 171
 			return [$v, $error];
172 172
 		else
173 173
 			return $this->validateRules($clean);
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
 	 */
181 181
 	protected function getDefault() {
182 182
 		$default = $this->default;
183
-		if( $default instanceof \Closure )
183
+		if ($default instanceof \Closure)
184 184
 			return $default();
185 185
 		else
186 186
 			return $this->cast($default);
187 187
 	}
188 188
 
189
-	protected function validateType( $v, $type ) {
189
+	protected function validateType($v, $type) {
190 190
 
191 191
 		$error = Error::NONE;
192 192
 
193
-		switch( $type ) {
193
+		switch ($type) {
194 194
 
195 195
 			case Type::TEXT:
196 196
 				$clean = trim((string) $v);
@@ -261,81 +261,81 @@  discard block
 block discarded – undo
261 261
 		}
262 262
 
263 263
 		// boolean fields will be null on error
264
-		if( $type == Type::BOOLEAN )
264
+		if ($type == Type::BOOLEAN)
265 265
 			$error = ($clean === null) ? Error::BOOLEAN : Error::NONE;
266
-		elseif( $clean === false )
266
+		elseif ($clean === false)
267 267
 			$error = Error::getTypeError($type);
268 268
 
269 269
 		return [$clean, $error];
270 270
 
271 271
 	}
272 272
 
273
-	protected function validateRules( $v ) {
273
+	protected function validateRules($v) {
274 274
 
275
-		if( $error = $this->validateRange($v) )
275
+		if ($error = $this->validateRange($v))
276 276
 			return [$v, $error];
277 277
 
278
-		elseif( $error = $this->validateLength($v) )
278
+		elseif ($error = $this->validateLength($v))
279 279
 			return [$v, $error];
280 280
 
281
-		elseif( $error = $this->validateValues($v) )
281
+		elseif ($error = $this->validateValues($v))
282 282
 			return [$v, $error];
283 283
 
284
-		elseif( $error = $this->validateRegex($v) )
284
+		elseif ($error = $this->validateRegex($v))
285 285
 			return [$v, $error];
286 286
 
287 287
 		return [$v, $error];
288 288
 
289 289
 	}
290 290
 
291
-	protected function validateRange( $v ) {
291
+	protected function validateRange($v) {
292 292
 
293
-		if( isset($this->rules['min']) && $v && ($v < $this->rules['min']) )
293
+		if (isset($this->rules['min']) && $v && ($v < $this->rules['min']))
294 294
 			return Error::MIN;
295 295
 
296
-		if( isset($this->rules['max']) && $v && ($v > $this->rules['max']) )
296
+		if (isset($this->rules['max']) && $v && ($v > $this->rules['max']))
297 297
 			return Error::MAX;
298 298
 
299 299
 		return Error::NONE;
300 300
 
301 301
 	}
302 302
 
303
-	protected function validateLength( $v ) {
303
+	protected function validateLength($v) {
304 304
 
305
-		if( isset($this->rules['min_length']) && mb_strlen($v) < $this->rules['min_length'] )
305
+		if (isset($this->rules['min_length']) && mb_strlen($v) < $this->rules['min_length'])
306 306
 			return Error::TOO_SHORT;
307 307
 
308
-		if( isset($this->rules['max_length']) && mb_strlen($v) > $this->rules['max_length'] )
308
+		if (isset($this->rules['max_length']) && mb_strlen($v) > $this->rules['max_length'])
309 309
 			return Error::TOO_LONG;
310 310
 
311 311
 		return Error::NONE;
312 312
 
313 313
 	}
314 314
 
315
-	protected function validateRegex( $v ) {
315
+	protected function validateRegex($v) {
316 316
 
317
-		if( isset($this->rules['regex']) && !preg_match($this->rules['regex'], $v) )
317
+		if (isset($this->rules['regex']) && !preg_match($this->rules['regex'], $v))
318 318
 			return Error::REGEX;
319 319
 
320 320
 		return Error::NONE;
321 321
 
322 322
 	}
323 323
 
324
-	protected function validateValues( $v ) {
324
+	protected function validateValues($v) {
325 325
 
326
-		if( isset($this->rules['values']) && !in_array($v, $this->rules['values']) )
326
+		if (isset($this->rules['values']) && !in_array($v, $this->rules['values']))
327 327
 			return Error::VALUE;
328 328
 
329 329
 		return Error::NONE;
330 330
 
331 331
 	}
332 332
 
333
-	protected function processRules( array $rules, $container = 'array' ) {
333
+	protected function processRules(array $rules, $container = 'array') {
334 334
 
335 335
 		$this->required = $rules['required'];
336 336
 		$this->nullable = $rules['nullable'];
337 337
 		$this->default  = $rules['default'];
338
-        $this->label    = $rules['label'];
338
+        $this->label = $rules['label'];
339 339
 
340 340
 		unset(
341 341
 			$rules['required'],
@@ -344,10 +344,10 @@  discard block
 block discarded – undo
344 344
 			$rules['label']
345 345
 		);
346 346
 
347
-		if( $this->isObject() ) {
347
+		if ($this->isObject()) {
348 348
 
349 349
 			// object fields must specify a class
350
-			if( empty($rules['class']) )
350
+			if (empty($rules['class']))
351 351
 				throw new \LogicException("Missing class name for item: {$this->name}");
352 352
 
353 353
 			// object fields are nullable by default
@@ -355,10 +355,10 @@  discard block
 block discarded – undo
355 355
 			$this->default  = null;
356 356
 
357 357
 		}
358
-		elseif( $this->isCollection() ) {
358
+		elseif ($this->isCollection()) {
359 359
 
360 360
 			// collection fields must specify a class
361
-			if( empty($rules['class']) )
361
+			if (empty($rules['class']))
362 362
 				throw new \LogicException("Missing item class for collection: {$this->name}");
363 363
 
364 364
 			$rules['container'] = empty($rules['container']) ? $container : $rules['container'];
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 
369 369
 				$container = $rules['container'];
370 370
 
371
-				if( $container == 'array' )
371
+				if ($container == 'array')
372 372
 					return [];
373 373
 				else
374 374
 					return new $container($rules['class']);
Please login to merge, or discard this patch.
src/Validator.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
 	 * @param  array $args array of arguments pass to the function
25 25
 	 * @return boolean
26 26
 	 */
27
-	public static function __callStatic( $name, $args ) {
27
+	public static function __callStatic($name, $args) {
28 28
 
29
-		$name = 'validate'. substr($name, 2);
29
+		$name = 'validate'.substr($name, 2);
30 30
 
31
-		if( !method_exists(__CLASS__, $name) )
31
+		if (!method_exists(__CLASS__, $name))
32 32
 			throw new \BadMethodCallException(sprintf("%s::%s()", get_called_class(), $name));
33 33
 
34 34
 		$failure = ($name == 'validateBoolean') ? null : false;
35 35
 
36
-		switch( count($args) ) {
36
+		switch (count($args)) {
37 37
 			case 1:
38 38
 				return static::$name($args[0]) !== $failure;
39 39
 			case 2:
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 
47 47
 
48
-	public static function isEmpty( $v, $type = Type::TEXT ) {
48
+	public static function isEmpty($v, $type = Type::TEXT) {
49 49
 
50
-		if( !$v || (is_scalar($v) && !trim($v)) )
50
+		if (!$v || (is_scalar($v) && !trim($v)))
51 51
 			return true;
52 52
 
53
-		switch( $type ) {
53
+		switch ($type) {
54 54
 
55 55
 			case Type::COLLECTION:
56 56
 				return count($v) == 0;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @param  mixed   $v
82 82
 	 * @return integer|false
83 83
 	 */
84
-	public static function validateInteger( $v ) {
84
+	public static function validateInteger($v) {
85 85
 		return $v ? filter_var($v, FILTER_VALIDATE_INT) : 0;
86 86
 	}
87 87
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @param  mixed   $v
92 92
 	 * @return float|false
93 93
 	 */
94
-	public static function validateFloat( $v ) {
94
+	public static function validateFloat($v) {
95 95
 		return $v ? filter_var($v, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND) : 0;
96 96
 	}
97 97
 
@@ -101,21 +101,21 @@  discard block
 block discarded – undo
101 101
 	 * @param  mixed   $v
102 102
 	 * @return boolean|null
103 103
 	 */
104
-	public static function validateBoolean( $v ) {
104
+	public static function validateBoolean($v) {
105 105
 		// FILTER_VALIDATE_BOOLEAN will return null if passed an actual boolean false
106 106
 		return ($v === false) ? $v : filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
107 107
 	}
108 108
 
109
-	public static function validateTimestamp( $v ) {
109
+	public static function validateTimestamp($v) {
110 110
 		$ts = filter_var($v, FILTER_VALIDATE_INT);
111
-		if( $ts === false )
111
+		if ($ts === false)
112 112
 			$ts = strtotime(str_replace('@', ' ', $v));
113 113
 		return $ts;
114 114
 	}
115 115
 
116
-	public static function validateDateTime( $v, $format = 'Y-m-d H:i:s' ) {
116
+	public static function validateDateTime($v, $format = 'Y-m-d H:i:s') {
117 117
 
118
-		if( !trim($v) || preg_match('/0000-00-00/', $v) )
118
+		if (!trim($v) || preg_match('/0000-00-00/', $v))
119 119
 			return '';
120 120
 
121 121
 		$ts = static::validateTimestamp($v);
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
 
125 125
 	}
126 126
 
127
-	public static function validateDate( $v ) {
127
+	public static function validateDate($v) {
128 128
 		return static::validateDateTime($v, 'Y-m-d');
129 129
 	}
130 130
 
131
-	public static function validateTime( $v ) {
131
+	public static function validateTime($v) {
132 132
 		return static::validateDateTime($v, 'H:i:s');
133 133
 	}
134 134
 
135
-	public static function validateYear( $v, $min = 1900, $max = 2155 ) {
135
+	public static function validateYear($v, $min = 1900, $max = 2155) {
136 136
 		$v = static::validateInteger($v);
137 137
 		return ($v >= $min) && ($v <= $max);
138 138
 	}
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 	 * @param  mixed   $v
143 143
 	 * @return string
144 144
 	 */
145
-	public static function validateIP( $v ) {
145
+	public static function validateIP($v) {
146 146
 		// if integer then convert to string
147
-		if( $ip = filter_var($v, FILTER_VALIDATE_INT) )
147
+		if ($ip = filter_var($v, FILTER_VALIDATE_INT))
148 148
 			$v = long2ip($ip);
149 149
 		return filter_var($v, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
150 150
 	}
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @param  mixed   $v
156 156
 	 * @return string|boolean
157 157
 	 */
158
-	public static function validateEmail( $v ) {
158
+	public static function validateEmail($v) {
159 159
 		return $v ? filter_var($v, FILTER_VALIDATE_EMAIL) : '';
160 160
 	}
161 161
 
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 	 * @param  mixed   $v
166 166
 	 * @return string|boolean
167 167
 	 */
168
-	public static function validateURL( $v ) {
168
+	public static function validateURL($v) {
169 169
 		return $v ? filter_var($v, FILTER_VALIDATE_URL) : '';
170 170
 	}
171 171
 
172
-	public static function validateJSON( $v ) {
172
+	public static function validateJSON($v) {
173 173
 
174 174
 		// if it's a string then try and decode it
175
-		if( is_string($v) )
175
+		if (is_string($v))
176 176
 			$v = json_decode($v, true);
177 177
 		// otherwise check we can encode it - we don't care about the function result
178 178
 		else
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
 
183 183
 	}
184 184
 
185
-	public static function validateObject( $v, $class, $nullable = false ) {
185
+	public static function validateObject($v, $class, $nullable = false) {
186 186
 
187
-		if( $v instanceof $class )
187
+		if ($v instanceof $class)
188 188
 			return $v;
189 189
 
190
-		elseif( $nullable && ($v === null) )
190
+		elseif ($nullable && ($v === null))
191 191
 			return $v;
192 192
 
193 193
 		return false;
Please login to merge, or discard this patch.