StringUtil   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A humanize() 0 8 1
A getClassBaseName() 0 5 2
A getLabelFromClass() 0 3 1
1
<?php
2
3
namespace Xiidea\EasyConfigBundle\Utility;
4
5
abstract class StringUtil
6
{
7
    public static function getLabelFromClass($class)
8
    {
9
        return ucfirst(static::humanize(static::getClassBaseName($class)));
10
    }
11
12
    public static function humanize($text)
13
    {
14
        $text = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $text);
15
        $text = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $text);
16
        $text = preg_replace('~\bdont\b~', 'don\'t', $text);
17
        $text = preg_replace('/_/', ' ', $text);;
18
19
        return mb_strtolower($text, 'UTF-8');
20
    }
21
22
    public static function getClassBaseName($class)
23
    {
24
        $class = is_object($class) ? get_class($class) : $class;
25
26
        return basename(str_replace('\\', '/', $class));
27
    }
28
}
29