Completed
Push — master ( 9458ed...7d322b )
by Henry
10:04
created

User::getPattern()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace Redaxscript\Validator;
3
4
use function preg_match;
5
6
/**
7
 * children class to validate user
8
 *
9
 * @since 4.3.0
10
 *
11
 * @package Redaxscript
12
 * @category Validator
13
 * @author Henry Ruhs
14
 */
15
16
class User implements ValidatorInterface
17
{
18
	/**
19
	 * pattern for user
20
	 *
21
	 * @var string
22
	 */
23
24
	protected $_pattern = '^[a-zA-Z0-9\._-]{3,100}$';
25
26
	/**
27
	 * get the pattern
28
	 *
29
	 * @since 4.3.0
30
	 *
31
	 * @return string
32
	 */
33
34
	public function getPattern() : string
35
	{
36
		return $this->_pattern;
37
	}
38
39
	/**
40
	 * validate the user
41
	 *
42
	 * @since 4.0.0
43
	 *
44
	 * @param string $user user to be validated
45
	 *
46
	 * @return bool
47 1
	 */
48
49 1
	public function validate(string $user = null) : bool
50
	{
51
		return preg_match('/' . $this->_pattern . '/', $user);
52
	}
53
}
54