Completed
Push — master ( 4deee6...b383ba )
by Zach
05:43 queued 03:44
created

Str::append()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Helpers;
4
5
class Str
6
{
7
    /**
8
     * The cache of studly-cased words.
9
     *
10
     * @var array
11
     */
12
    protected static $studlyCache = [];
13
14
    /**
15
     * Create StudlyCase string from _ separated string.
16
     *
17
     * @param string $value
18
     *
19
     * @return string
20
     */
21
    public static function studly($value)
22
    {
23
        static $studlyCache = [];
24
25
        $key = $value;
26
27
        if (isset($studlyCache[$key])) {
28
            return $studlyCache[$key];
29
        }
30
31
        $value = ucwords(str_replace(['-', '_'], ' ', $value));
32
33
        return $studlyCache[$key] = str_replace(' ', '', $value);
34
    }
35
36
    /**
37
     * Append a character to a string if it doesn't already exist.
38
     *
39
     * @param string $value
40
     * @param string $char
41
     *
42
     * @return string
43
     */
44
    public static function append($value, $char)
45
    {
46
        if (substr($value, -1) !== $char) {
47
            $value .= $char;
48
        }
49
50
        return $value;
51
    }
52
}
53