StudlyCaps::join()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 4
nc 1
nop 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