Completed
Push — master ( c6ec0f...bab290 )
by Magnar Ovedal
03:36
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 convert() 0 20 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\WordConverter;
6
7
use Traversable;
8
9
final class MixedCase implements WordConverterInterface
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14 2
    public function convert(string $word): Traversable
15
    {
16 2
        if ($word === '') {
17 2
            yield '';
18 2
            return;
19
        }
20
21 2
        $char = mb_substr($word, 0, 1);
22
23 2
        $chars = [$char];
24 2
        if ($char !== mb_strtolower($char)) {
25 2
            $chars[] = mb_strtolower($char);
26
        }
27 2
        if ($char !== mb_strtoupper($char)) {
28 2
            $chars[] = mb_strtoupper($char);
29
        }
30
31 2
        foreach ($this->convert(mb_substr($word, 1)) as $suffix) {
32 2
            foreach ($chars as $char) {
33 2
                yield $char.$suffix;
34
            }
35
        }
36 2
    }
37
}
38