Format   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doStraightShorten() 0 7 2
A doShorten() 0 8 2
1
<?php
2
3
/**
4
 * String Format
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Strings
10
 * @author    Daniel Burke <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\strings;
17
18
/**
19
 * String Format
20
 *
21
 * @category  Core
22
 * @package   Strings
23
 * @author    Daniel Burke <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Format
30
{
31
    /**
32
     * Shortens a string.
33
     *
34
     * @param string $string      the input string
35
     * @param int    $count       the final length of the string
36
     * @param string $placeholder the placeholder string
37
     *
38
     * @return string the short string
39
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
40
     
41
    public static function doStraightShorten($string, $count, $placeholder = '...')
42
    {
43
        if (strlen($string.$placeholder) >= $count) {
44
            $string = substr($string, 0, $count) . $placeholder;
45
        }
46
        return $string; 
47
    }    
48
49
    /**
50
     * Shortens a string.
51
     *
52
     * @param string $string      the input string
53
     * @param int    $count       the final length of the string
54
     * @param string $placeholder the placeholder string
55
     *
56
     * @return string the short string without breaking a word
57
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
58
     
59
    public static function doShorten($string, $count, $placeholder = ' ...')
60
    {
61
        if (strlen($string.$placeholder) >= $count) {
62
            $string = substr($string, 0, $count);
63
            $string = substr($string, 0, strrpos($string, ' ')) . $placeholder;
64
        }
65
        return $string;
66
    }   
67
}
68