Completed
Push — 0.2.1 ( c28689...fcf990 )
by Anton
04:29
created

Validate::string()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4286
c 1
b 0
f 0
cc 3
eloc 3
nc 3
nop 4
1
<?php
2
3
namespace Utils {
4
5
	use Str;
6
7
	class Validate extends \Validate {
8
9
		# Validate auth code
10
11
		public static function authCode(string $value) {
12
13
			return (preg_match(REGEX_USER_AUTH_CODE, $value) ? $value : false);
14
		}
15
16
		# Validate user name
17
18
		public static function userName(string $value) {
19
20
			$min = CONFIG_USER_NAME_MIN_LENGTH; $max = CONFIG_USER_NAME_MAX_LENGTH;
21
22
			return ((preg_match(REGEX_USER_NAME, $value) && Str::between($value, $min, $max)) ? $value : false);
23
		}
24
25
		# Validate user password
26
27
		public static function userPassword(string $value) {
28
29
			$min = CONFIG_USER_PASSWORD_MIN_LENGTH; $max = CONFIG_USER_PASSWORD_MAX_LENGTH;
30
31
			return ((preg_match(REGEX_USER_PASSWORD, $value) && Str::between($value, $min, $max)) ? $value : false);
32
		}
33
34
		# Validate user email
35
36
		public static function userEmail(string $value) {
37
38
			return self::email($value);
39
		}
40
41
		# Validate file or directory name
42
43
		public static function fileName(string $value) {
44
45
			return (preg_match(REGEX_FILE_NAME, $value) ? $name : false);
0 ignored issues
show
Bug introduced by
The variable $name does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
46
		}
47
48
		# Validate url
49
50
		public static function url(string $value) {
51
52
			if (false === ($value = parent::url($value))) return false;
53
54
			if (!preg_match('/^https?:\/\//', $value)) return false;
55
56
			# ------------------------
57
58
			return rtrim($value, '/');
59
		}
60
	}
61
}
62