Completed
Push — master ( c6ec0f...bab290 )
by Magnar Ovedal
03:36
created

MixedCase::convert()   A

Complexity

Conditions 6
Paths 13

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 13
nop 1
dl 0
loc 20
ccs 13
cts 13
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
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