SplitCamelCaseWordsFormatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 10
ccs 7
cts 7
cp 1
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 11 2
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Csv-Machine package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Csv\Formatter;
13
14
15
/**
16
 * Class SplitCamelCaseWordsFormatter
17
 *
18
 * @author  Dan McAdams
19
 * @package RoadBunch\Csv\Formatter
20
 */
21
class SplitCamelCaseWordsFormatter extends AbstractFormatter
22
{
23
    /**
24
     * @param array $data
25
     *
26
     * @return array
27
     * @throws \RoadBunch\Csv\Exception\FormatterResultException
28
     */
29
    public static function format(array $data): array
30
    {
31 2
        return self::applyFilter(function ($var) {
32 2
            $regex = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z\.])(?=[A-Z][a-z])/x';
33 2
            $words = preg_split($regex, $var, $limit = -1, PREG_SPLIT_NO_EMPTY);
34
35 2
            if (!empty($words)) {
36 2
                return implode(' ', $words);
37
            };
38 1
            return $var;
39 2
        }, $data);
40
    }
41
}
42