Completed
Push — v2.0.x ( 94c950...c40792 )
by Florent
02:29
created

StringUtil   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A strlen() 0 4 2
A substr() 0 4 2
A str_pad() 0 4 2
A mb_pad_str() 0 4 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Util;
13
14
/**
15
 * Class String.
16
 */
17
final class StringUtil
18
{
19
    public static function strlen($string)
20
    {
21
        return function_exists('mb_strlen') ? mb_strlen($string, '8bit') : strlen($string);
22
    }
23
24
    public static function substr($string, $start, $length = null)
25
    {
26
        return function_exists('mb_substr') ? mb_substr($string, $start, $length, '8bit') : substr($string, $start, $length);
27
    }
28
29
    public static function str_pad($input, $pad_length, $pad_string = null, $pad_style = null)
30
    {
31
        return function_exists('mb_strlen') ? self::mb_pad_str($input, $pad_length, $pad_string, $pad_style) : str_pad($input, $pad_length, $pad_string, $pad_style);
32
    }
33
34
    private static function mb_pad_str($input, $pad_length, $pad_string = null, $pad_style = null)
35
    {
36
        return str_pad($input, strlen($input)-mb_strlen($input, '8bit')+$pad_length, $pad_string, $pad_style);
37
    }
38
}
39