Passed
Push — main ( 90c8f5...cf7c53 )
by Daniel
01:54
created

SplitCamelCaseFormatter::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace RoadBunch\StringBean;
5
6
7
class SplitCamelCaseFormatter extends AbstractFormatter
8
{
9
    public function format(string $string): string
10
    {
11
        $regex = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z\.])(?=[A-Z][a-z])/x';
12
        $words = preg_split($regex, $string, limit: -1, flags: PREG_SPLIT_NO_EMPTY);
13
14
        if (!empty($words)) {
15
            return implode(' ', $words);
16
        };
17
        return $string;
18
    }
19
}
20