Intl   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getFilters() 0 8 1
A twig_localized_date_filter() 0 23 2
1
<?php
2
3
namespace DoS\ResourceBundle\Twig\Extension;
4
5
class Intl extends \Twig_Extensions_Extension_Intl
6
{
7
    protected $traditional = true;
8
9
    public function __construct($traditional = true)
10
    {
11
        parent::__construct();
12
13
        $this->traditional = $traditional;
14
    }
15
16
    public function getFilters()
17
    {
18
        return array(
19
            new \Twig_SimpleFilter('localizeddate', array($this, 'twig_localized_date_filter'), array('needs_environment' => true)),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
            new \Twig_SimpleFilter('localizednumber', 'twig_localized_number_filter'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
21
            new \Twig_SimpleFilter('localizedcurrency', 'twig_localized_currency_filter'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
        );
23
    }
24
25
    public function twig_localized_date_filter(\Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null)
26
    {
27
        $date = twig_date_converter($env, $date, $timezone);
28
29
        $formatValues = array(
30
            'none' => \IntlDateFormatter::NONE,
31
            'short' => \IntlDateFormatter::SHORT,
32
            'medium' => \IntlDateFormatter::MEDIUM,
33
            'long' => \IntlDateFormatter::LONG,
34
            'full' => \IntlDateFormatter::FULL,
35
        );
36
37
        $formatter = \IntlDateFormatter::create(
38
            $locale,
39
            $formatValues[$dateFormat],
40
            $formatValues[$timeFormat],
41
            $date->getTimezone()->getName(),
42
            $this->traditional ? \IntlDateFormatter::TRADITIONAL : \IntlDateFormatter::GREGORIAN,
43
            $format
44
        );
45
46
        return $formatter->format($date->getTimestamp());
47
    }
48
}
49