Completed
Push — master ( 8474c3...33b080 )
by Andrew
03:17
created

StringUtil::capitalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KRDigital\NamesDetector\Util;
6
7
class StringUtil
8
{
9 5
    public static function capitalize(string $input): string
10
    {
11 5
        $result = [];
12
13 5
        foreach (\explode(' ', $input) as $word) {
14 5
            $result[] = \sprintf('%s%s', \mb_strtoupper(\mb_substr($word, 0, 1)), \mb_strtolower(\mb_substr($word, 1, \mb_strlen($word) - 1)));
15
        }
16
17 5
        return \implode(' ', $result);
18
    }
19
}
20