Completed
Push — 0.2.1 ( dab97b...c28689 )
by Anton
05:05
created

Validate::fileName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 2
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace Utils {
4
5
	use Str;
6
7
	class Validate extends \Validate {
8
9
		# Validate string using regex and length limitors
10
11
		private static function string(string $string, string $regex, int $min, int $max) {
12
13
			if (!preg_match($regex, $string)) return false;
14
15
			return ((Str::between($string, $min, $max)) ? $string : false);
16
		}
17
18
		# Validate auth code
19
20
		public static function authCode(string $value) {
21
22
			return (preg_match(REGEX_USER_AUTH_CODE, $value) ? $code : false);
0 ignored issues
show
Bug introduced by
The variable $code 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...
23
		}
24
25
		# Validate user name
26
27
		public static function userName(string $value) {
28
29
			$min = CONFIG_USER_NAME_MIN_LENGTH; $max = CONFIG_USER_NAME_MAX_LENGTH;
30
31
			return self::string($value, REGEX_USER_NAME, $min, $max);
32
		}
33
34
		# Validate user password
35
36
		public static function userPassword(string $value) {
37
38
			$min = CONFIG_USER_PASSWORD_MIN_LENGTH; $max = CONFIG_USER_PASSWORD_MAX_LENGTH;
39
40
			return self::string($value, REGEX_USER_PASSWORD, $min, $max);
41
		}
42
43
		# Validate user email
44
45
		public static function userEmail(string $value) {
46
47
			return self::email($value);
48
		}
49
50
		# Validate file or directory name
51
52
		public static function fileName(string $value) {
53
54
			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...
55
		}
56
57
		# Validate url
58
59
		public static function url(string $value) {
60
61
			if (false === ($value = parent::url($value))) return false;
62
63
			if (!preg_match('/^https?:\/\//', $value)) return false;
64
65
			# ------------------------
66
67
			return rtrim($value, '/');
68
		}
69
	}
70
}
71