CamelKeysNormalizerWithLeadingUnderscore   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalizeString() 0 16 3
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\RestBundle\Normalizer;
13
14
/**
15
 * Normalizes the array by changing its keys from underscore to camel case, while
16
 * leaving leading underscores unchanged.
17
 *
18
 * @author Lukas Kahwe Smith <[email protected]>
19
 *
20
 * @internal
21
 */
22
class CamelKeysNormalizerWithLeadingUnderscore extends CamelKeysNormalizer
23
{
24
    /**
25
     * Normalizes a string while leaving leading underscores unchanged.
26
     *
27
     * @return string
28
     */
29 2
    protected function normalizeString(string $string)
30
    {
31 2
        if (false === strpos($string, '_')) {
32 1
            return $string;
33
        }
34
35 2
        $offset = strspn($string, '_');
36 2
        if ($offset) {
37 1
            $underscorePrefix = substr($string, 0, $offset);
38 1
            $string = substr($string, $offset);
39
        } else {
40 1
            $underscorePrefix = '';
41
        }
42
43 2
        return $underscorePrefix.parent::normalizeString($string);
44
    }
45
}
46