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

CamelKeysNormalizerWithLeadingUnderscore   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
ccs 7
cts 10
cp 0.7
rs 10

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
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