StudlyCaps   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A split() 0 12 1
A join() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of Camel.
5
 *
6
 * (c) Matthieu Moquet <[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 Camel\Format;
13
14
/**
15
 * Format to handle StudlyCaps.
16
 *
17
 * @author Matthieu Moquet <[email protected]>
18
 */
19
class StudlyCaps implements FormatInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function split($word)
25
    {
26
        // Match camelCase
27
        $pattern = '/   # Match position between camelCase "words".
28
            (?<=[a-z])  # Position is after a lowercase,
29
            (?=[A-Z])   # and before an uppercase letter.
30
            /x';
31
32
        $words = preg_split($pattern, $word);
33
34
        return $words;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function join(array $words)
41
    {
42
        // Ensure words are lowercase
43
        $words = array_map('strtolower', $words);
44
45
        // UC first each words
46
        $words = array_map('ucfirst', $words);
47
48
        return implode('', $words);
49
    }
50
}
51