Completed
Branch 0.2.1 (e70612)
by Anton
09:15
created

Validate   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 3
A code() 0 4 2
A userName() 0 6 1
A userPassword() 0 6 1
1
<?php
2
3
namespace Modules\Auth {
4
5
	use Str;
6
7
	abstract class Validate {
8
9
		# Validate param
10
11
		private static function validate(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 code(string $code) {
21
22
			return (preg_match(REGEX_USER_AUTH_CODE, $code) ? $code : false);
23
		}
24
25
		# Validate user name
26
27
		public static function userName(string $name) {
28
29
			$min = CONFIG_USER_NAME_MIN_LENGTH; $max = CONFIG_USER_NAME_MAX_LENGTH;
30
31
			return self::validate($name, REGEX_USER_NAME, $min, $max);
32
		}
33
34
		# Validate user password
35
36
		public static function userPassword(string $password) {
37
38
			$min = CONFIG_USER_PASSWORD_MIN_LENGTH; $max = CONFIG_USER_PASSWORD_MAX_LENGTH;
39
40
			return self::validate($password, REGEX_USER_PASSWORD, $min, $max);
41
		}
42
	}
43
}
44