Completed
Push — master ( 6ebbd6...dc44ee )
by Guilh
04:39
created

normalizeString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.243

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 10
cp 0.7
rs 9.4286
cc 3
eloc 10
nc 3
nop 1
crap 3.243
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
class CamelKeysNormalizerWithLeadingUnderscore extends CamelKeysNormalizer
21
{
22
    /**
23
     * Normalizes a string while leaving leading underscores unchanged.
24
     *
25
     * @param string $string
26
     *
27
     * @return string
28
     */
29 1
    protected function normalizeString($string)
30
    {
31 1
        if (false === strpos($string, '_')) {
32 1
            return $string;
33
        }
34
35 1
        $offset = strspn($string, '_');
36 1
        if ($offset) {
37
            $underscorePrefix = substr($string, 0, $offset);
38
            $string = substr($string, $offset);
39
        } else {
40 1
            $underscorePrefix = '';
41
        }
42
43 1
        return $underscorePrefix.parent::normalizeString($string);
44
    }
45
}
46