Strings   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A snakeCase() 0 11 2
1
<?php
2
3
namespace LeoCarmo\TelegramBot\Helpers;
4
5
class Strings
6
{
7
8
    /**
9
     * The cache for snake-cased strings.
10
     *
11
     * @var array
12
     */
13
    protected static $snakeCase = [];
14
15
    /**
16
     * Convert a string to snake case.
17
     *
18
     * @param  string  $value
19
     * @return string
20
     */
21
    public static function snakeCase($value) : string
22
    {
23
        $key = $value;
24
25
        if (isset(static::$snakeCase[$key])) {
26
            return static::$snakeCase[$key];
27
        }
28
29
        $value = preg_replace('/[^a-z]/', '_', mb_strtolower($value));
30
31
        return static::$snakeCase[$key] = $value;
32
    }
33
34
}