ShortCodeConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 30
rs 10
c 2
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A do() 0 15 2
A convertLocale() 0 11 3
1
<?php
2
3
namespace PiedWeb\CMSBundle\Service;
4
5
class ShortCodeConverter
6
{
7
    public static function do($string, $locale = null)
8
    {
9
        //var_dump($string); exit;
10
        if ($locale) {
11
            setlocale(LC_TIME, self::convertLocale($locale));
12
        }
13
14
        //$string = preg_replace('/date\([\'"]?([a-z% ]+)[\'"]?\)/i',
15
        //  strftime(strpos('\1', '%') ? '\1': '%\1'), $string);
16
        $string = preg_replace('/date\([\'"]?%?Y[\'"]?\)/i', strftime('%Y'), $string);
17
        $string = preg_replace('/date\([\'"]?%?(B|M)[\'"]?\)/i', strftime('%B'), $string);
18
        $string = preg_replace('/date\([\'"]?%?A[\'"]?\)/i', strftime('%A'), $string);
19
        $string = preg_replace('/date\([\'"]?%?e[\'"]?\)/i', strftime('%e'), $string);
20
21
        return $string;
22
    }
23
24
    public static function convertLocale($locale)
25
    {
26
        if ('fr' == $locale) {
27
            return 'fr_FR';
28
        }
29
30
        if ('en' == $locale) {
31
            return 'en_UK';
32
        }
33
34
        return $locale;
35
    }
36
}
37