Passed
Push — master ( 14b05a...fa6902 )
by Daniel
02:41
created

SplitCamelCaseWordsFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A format() 0 3 1
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 implements FormatterInterface
22
{
23
    /** @var FormatterInterface */
24
    protected $formatter;
25
26
    /**
27
     * SplitCamelCaseWordsFormatter constructor.
28
     */
29
    public function __construct()
30
    {
31 3
        $callback = function ($var) {
32 2
            $regEx  = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/x';
33 2
            $words  = preg_split($regEx, $var);
34 2
            return implode(' ', $words);
0 ignored issues
show
Bug introduced by
It seems like $words can also be of type false; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
            return implode(' ', /** @scrutinizer ignore-type */ $words);
Loading history...
35 3
        };
36 3
        $this->formatter = new Formatter($callback);
37 3
    }
38
39
    /**
40
     * @param array $data
41
     *
42
     * @return array
43
     */
44 2
    public function format(array $data): array
45
    {
46 2
        return $this->formatter->format($data);
47
    }
48
}
49