Validate   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 16
lcom 0
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A authCode() 0 4 2
A userName() 0 6 3
A userPassword() 0 6 3
A userEmail() 0 4 1
A templateComponentName() 0 4 2
A fileName() 0 4 2
A url() 0 10 3
1
<?php
2
3
/**
4
 * @package Cadmium\System\Utils
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Utils {
11
12
	use Str;
13
14
	class Validate extends \Validate {
15
16
		/**
17
		 * Validate an authorization code
18
		 *
19
		 * @return string|false : the code or false on failure
20
		 */
21
22
		public static function authCode(string $value) {
23
24
			return (preg_match(REGEX_USER_AUTH_CODE, $value) ? $value : false);
25
		}
26
27
		/**
28
		 * Validate a user name
29
		 *
30
		 * @return string|false : the name or false on failure
31
		 */
32
33
		public static function userName(string $value) {
34
35
			$min = CONFIG_USER_NAME_MIN_LENGTH; $max = CONFIG_USER_NAME_MAX_LENGTH;
36
37
			return ((preg_match(REGEX_USER_NAME, $value) && Str::between($value, $min, $max)) ? $value : false);
38
		}
39
40
		/**
41
		 * Validate a user password
42
		 *
43
		 * @return string|false : the password or false on failure
44
		 */
45
46
		public static function userPassword(string $value) {
47
48
			$min = CONFIG_USER_PASSWORD_MIN_LENGTH; $max = CONFIG_USER_PASSWORD_MAX_LENGTH;
49
50
			return ((preg_match(REGEX_USER_PASSWORD, $value) && Str::between($value, $min, $max)) ? $value : false);
51
		}
52
53
		/**
54
		 * Validate a user email
55
		 *
56
		 * @return string|false : the email or false on failure
57
		 */
58
59
		public static function userEmail(string $value) {
60
61
			return self::email($value);
62
		}
63
64
		/**
65
		 * Validate a template component name
66
		 *
67
		 * @return string|false : the name or false on failure
68
		 */
69
70
		public static function templateComponentName(string $value) {
71
72
			return (preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $value) ? $value : false);
73
		}
74
75
		/**
76
		 * Validate a file/directory name
77
		 *
78
		 * @return string|false : the name or false on failure
79
		 */
80
81
		public static function fileName(string $value) {
82
83
			return (preg_match(REGEX_FILE_NAME, $value) ? $value : false);
84
		}
85
86
		/**
87
		 * Validate a url
88
		 *
89
		 * @return string|false : the url or false on failure
90
		 */
91
92
		public static function url(string $value) {
93
94
			if (false === ($value = parent::url($value))) return false;
95
96
			if (!preg_match('/^https?:\/\//', $value)) return false;
97
98
			# ------------------------
99
100
			return rtrim($value, '/');
101
		}
102
	}
103
}
104