Alias   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 0
dl 0
loc 71
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matchSystem() 0 4 1
A getPattern() 0 4 1
A validate() 0 4 1
1
<?php
2
namespace Redaxscript\Validator;
3
4
use function in_array;
5
use function preg_match;
6
7
/**
8
 * children class to validate general and default alias
9
 *
10
 * @since 2.2.0
11
 *
12
 * @package Redaxscript
13
 * @category Validator
14
 * @author Henry Ruhs
15
 * @author Sven Weingartner
16
 */
17
18
class Alias implements ValidatorInterface
19
{
20
	/**
21
	 * pattern for alias
22
	 *
23
	 * @var string
24
	 */
25
26
	protected $_pattern = '^[a-zA-Z0-9-]{3,100}$';
27
28
	/**
29
	 * array of system alias
30
	 *
31
	 * @var array
32
	 */
33
34
	protected $_systemArray =
35
	[
36
		'admin',
37
		'login',
38
		'recover',
39
		'reset',
40
		'logout',
41
		'register',
42
		'module',
43
		'search'
44
	];
45
46
	/**
47
	 * get the pattern
48
	 *
49
	 * @since 4.3.0
50
	 *
51
	 * @return string
52
	 */
53
54 1
	public function getPattern() : string
55
	{
56 1
		return $this->_pattern;
57
	}
58
59
	/**
60
	 * validate the alias
61
	 *
62
	 * @since 4.3.0
63
	 *
64
	 * @param string $alias alias to be validated
65
	 *
66
	 * @return bool
67
	 */
68
69 12
	public function validate(string $alias = null) : bool
70
	{
71 12
		return preg_match('/' . $this->_pattern . '/', $alias);
72
	}
73
74
	/**
75
	 * match system alias
76
	 *
77
	 * @since 4.3.0
78
	 *
79
	 * @param string $alias alias to be matched
80
	 *
81
	 * @return bool
82
	 */
83
84 3
	public function matchSystem(string $alias = null) : bool
85
	{
86 3
		return in_array($alias, $this->_systemArray);
87
	}
88
}
89