PasswordRequirementsValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 7 3
A hasAtLeastOneNumber() 0 4 1
A hasAtLeastOneUnicodeUpperCaseLetter() 0 4 1
A hasAtLeastOneUnicodeLowerCaseLetter() 0 4 1
1
<?php
2
/*
3
 * This file is part of the StfalconApiBundle.
4
 *
5
 * (c) Stfalcon LLC <stfalcon.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace StfalconStudio\ApiBundle\Util;
14
15
/**
16
 * PasswordRequirementsValidator.
17
 */
18
class PasswordRequirementsValidator
19
{
20
    public const NUMBER_REGEXP = '/[\d]{1,}/';
21
22
    public const LOWERCASE_LETTER_REGEXP = '/\p{Ll}{1,}/u';
23
24
    public const UPPERCASE_LETTER_REGEXP = '/\p{Lu}{1,}/u';
25
26
    /**
27
     * @param string $password
28
     *
29
     * @return bool
30
     */
31
    public function isValid(string $password): bool
32
    {
33
        return $this->hasAtLeastOneNumber($password)
34
            && $this->hasAtLeastOneUnicodeUpperCaseLetter($password)
35
            && $this->hasAtLeastOneUnicodeLowerCaseLetter($password)
36
        ;
37
    }
38
39
    /**
40
     * @param string $password
41
     *
42
     * @return bool
43
     */
44
    private function hasAtLeastOneNumber(string $password): bool
45
    {
46
        return (bool) \preg_match(self::NUMBER_REGEXP, $password);
47
    }
48
49
    /**
50
     * @param string $password
51
     *
52
     * @return bool
53
     */
54
    private function hasAtLeastOneUnicodeUpperCaseLetter(string $password): bool
55
    {
56
        return (bool) \preg_match(self::UPPERCASE_LETTER_REGEXP, $password);
57
    }
58
59
    /**
60
     * @param string $password
61
     *
62
     * @return bool
63
     */
64
    private function hasAtLeastOneUnicodeLowerCaseLetter(string $password): bool
65
    {
66
        return (bool) \preg_match(self::LOWERCASE_LETTER_REGEXP, $password);
67
    }
68
}
69