Passed
Push — master ( 3f8caf...ee340d )
by Richard
06:01 queued 11s
created

smarty_modifier_capitalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Smarty plugin
4
 * @package Smarty
5
 * @subpackage plugins
6
 */
7
8
9
/**
10
 * Smarty capitalize modifier plugin
11
 *
12
 * Type:     modifier<br>
13
 * Name:     capitalize<br>
14
 * Purpose:  capitalize words in the string
15
 * @link http://smarty.php.net/manual/en/language.modifiers.php#LANGUAGE.MODIFIER.CAPITALIZE
16
 *      capitalize (Smarty online manual)
17
 * @author   Monte Ohrt <monte at ohrt dot com>
18
 * @param string
19
 * @return string
20
 */
21
function smarty_modifier_capitalize($string, $uc_digits = false)
22
{
23
    smarty_modifier_capitalize_ucfirst(null, $uc_digits);
24
    return preg_replace_callback('!\'?\b\w(\w|\')*\b!', 'smarty_modifier_capitalize_ucfirst', $string);
25
}
26
27
function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
28
{
29
    static $_uc_digits = false;
30
    
31
    if(isset($uc_digits)) {
32
        $_uc_digits = $uc_digits;
33
        return;
34
    }
35
    
36
    if(substr($string[0],0,1) != "'" && !preg_match("!\d!",$string[0]) || $_uc_digits)
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: (substr($string[0], 0, 1...ing[0])) || $_uc_digits, Probably Intended Meaning: substr($string[0], 0, 1)...ing[0]) || $_uc_digits)
Loading history...
37
        return ucfirst($string[0]);
38
    else
39
        return $string[0];
40
}
41
42
43
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
44