ShortCodeConverter::convertLocale()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 10
c 2
b 0
f 0
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