Uppercase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 6 2
1
<?php
2
/*
3
    Password Strength Library
4
    Copyright (C) 2019 CustomerGauge
5
    [email protected]
6
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU Lesser General Public
9
    License as published by the Free Software Foundation; either
10
    version 3 of the License, or (at your option) any later version.
11
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
    Lesser General Public License for more details.
16
17
    You should have received a copy of the GNU Lesser General Public License
18
    along with this program; if not, write to the Free Software Foundation,
19
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
*/
21
22
declare(strict_types=1);
23
24
namespace CustomerGauge\Password\Rule;
25
26
use CustomerGauge\Password\Exception\InvalidCharacterType;
27
use CustomerGauge\Password\Rule;
28
29
use function count;
30
use function preg_match;
31
32
final class Uppercase implements Rule
33
{
34
    private int $count;
35
36 2
    public function __construct(int $count = 1)
37
    {
38 2
        $this->count = $count;
39 2
    }
40
41 2
    public function __invoke(string $password): void
42
    {
43 2
        preg_match('/[A-Z]/', $password, $matches);
44
45 2
        if (count($matches) < $this->count) {
46 2
            throw InvalidCharacterType::requires('uppercase', $this->count, count($matches));
47
        }
48
    }
49
}
50