Passed
Push — master ( 12ec71...6a4e7a )
by Magnar Ovedal
02:59
created

MixedCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 25
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 20 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\WordFormatter;
6
7
use Stadly\PasswordPolice\WordFormatter;
8
use Traversable;
9
10
final class MixedCase implements WordFormatter
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15 2
    public function apply(string $word): Traversable
16
    {
17 2
        if ($word === '') {
18 2
            yield '';
19 2
            return;
20
        }
21
22 2
        $char = mb_substr($word, 0, 1);
23
24 2
        $chars = [$char];
25 2
        if ($char !== mb_strtolower($char)) {
26 2
            $chars[] = mb_strtolower($char);
27
        }
28 2
        if ($char !== mb_strtoupper($char)) {
29 2
            $chars[] = mb_strtoupper($char);
30
        }
31
32 2
        foreach ($this->apply(mb_substr($word, 1)) as $suffix) {
33 2
            foreach ($chars as $formattedChar) {
34 2
                yield $formattedChar.$suffix;
35
            }
36
        }
37 2
    }
38
}
39