Validator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasSymbols() 0 3 1
A matchRegex() 0 3 1
A hasUpper() 0 3 1
A isRegex() 0 3 1
A hasNumbers() 0 3 1
A hasLower() 0 3 1
A hasLetters() 0 3 1
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Mvc\Controller\Validators;
26
27
/**
28
 * Class Validator
29
 *
30
 * @package SP\Util
31
 */
32
final class Validator
33
{
34
    /**
35
     * @param string $string
36
     *
37
     * @return bool
38
     */
39
    public static function hasLetters(string $string)
40
    {
41
        return preg_match('#[a-z]+#i', $string) === 1;
42
    }
43
44
    /**
45
     * @param string $string
46
     *
47
     * @return bool
48
     */
49
    public static function hasNumbers(string $string)
50
    {
51
        return preg_match('#[\d]+#', $string) === 1;
52
    }
53
54
    /**
55
     * @param string $string
56
     *
57
     * @return bool
58
     */
59
    public static function hasUpper(string $string)
60
    {
61
        return preg_match('#[A-Z]+#', $string) === 1;
62
    }
63
64
    /**
65
     * @param string $string
66
     *
67
     * @return bool
68
     */
69
    public static function hasLower(string $string)
70
    {
71
        return preg_match('#[a-z]+#', $string) === 1;
72
    }
73
74
    /**
75
     * @param string $string
76
     *
77
     * @return bool
78
     */
79
    public static function hasSymbols(string $string)
80
    {
81
        return preg_match('#[$-/:-?{-~!"^_`\[\]]+#', $string) === 1;
82
    }
83
84
    /**
85
     * @param string $string
86
     * @param string $regex
87
     *
88
     * @return bool
89
     */
90
    public static function matchRegex(string $string, string $regex)
91
    {
92
        return preg_match('#' . str_replace('#', '\#', $regex) . '#', $string) === 1;
93
    }
94
95
    /**
96
     * @param string $regex
97
     *
98
     * @return bool
99
     */
100
    public static function isRegex(string $regex)
101
    {
102
        return @preg_match('#' . str_replace('#', '\#', $regex) . '#', null);
0 ignored issues
show
Bug Best Practice introduced by
The expression return @preg_match('#' ....', $regex) . '#', null) returns the type integer which is incompatible with the documented return type boolean.
Loading history...
103
    }
104
}