Completed
Push — experimental/sf ( 048f3e...a2a322 )
by Ryo
92:10 queued 85:04
created

IntlExtension::date_day_with_weekday()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 19
ccs 0
cts 12
cp 0
crap 6
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Twig\Extension;
15
16
use Twig\Environment;
17
use Twig\Extension\AbstractExtension;
18
use Twig\TwigFilter;
19
20
class IntlExtension extends AbstractExtension
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 241
    public function getFilters()
26
    {
27
        return [
28 241
            new TwigFilter('date_day', [$this, 'date_day'], ['needs_environment' => true]),
29 241
            new TwigFilter('date_min', [$this, 'date_min'], ['needs_environment' => true]),
30 241
            new TwigFilter('date_sec', [$this, 'date_sec'], ['needs_environment' => true]),
31 241
            new TwigFilter('date_day_with_weekday', [$this, 'date_day_with_weekday'], ['needs_environment' => true]),
32
        ];
33
    }
34
35
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$date" missing
Loading history...
36
     * localizeddate('medium', 'none')のショートカット.
37
     *
38
     * 2015/08/28のように、日までのフォーマットで表示します(localeがjaの場合).
39
     * null,空文字に対して利用した場合は、空文字を返却します.
40
     *
41
     * @param Environment $env
42
     * @param $date
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
43
     *
44
     * @return bool|string
45
     */
46 1
    public function date_day(Environment $env, $date)
0 ignored issues
show
Coding Style introduced by
Method name "IntlExtension::date_day" is not in camel caps format
Loading history...
47
    {
48 1
        if (!$date) {
49
            return '';
50
        }
51
52 1
        return \twig_localized_date_filter($env, $date, 'medium', 'none');
53
    }
54
55
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$date" missing
Loading history...
56
     * localizeddate('medium', 'short')のショートカット.
57
     *
58
     * 2015/08/28 16:13のように、分までのフォーマットで表示します(localeがjaの場合).
59
     * null,空文字に対して利用した場合は、空文字を返却します.
60
     *
61
     * @param Environment $env
62
     * @param $date
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
63
     *
64
     * @return bool|string
65
     */
66 147
    public function date_min(Environment $env, $date)
0 ignored issues
show
Coding Style introduced by
Method name "IntlExtension::date_min" is not in camel caps format
Loading history...
67
    {
68 147
        if (!$date) {
69 146
            return '';
70
        }
71
72 6
        return \twig_localized_date_filter($env, $date, 'medium', 'short');
73
    }
74
75
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$date" missing
Loading history...
76
     * localizeddate('medium', 'medium')のショートカット.
77
     *
78
     * 2015/08/28 16:13:05(localeがjaの場合).
79
     * null,空文字に対して利用した場合は、空文字を返却します.
80
     *
81
     * @param Environment $env
82
     * @param $date
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
83
     *
84
     * @return bool|string
85
     */
86 5
    public function date_sec(Environment $env, $date)
0 ignored issues
show
Coding Style introduced by
Method name "IntlExtension::date_sec" is not in camel caps format
Loading history...
87
    {
88 5
        if (!$date) {
89 2
            return '';
90
        }
91
92 4
        return \twig_localized_date_filter($env, $date, 'medium', 'medium');
93
    }
94
95
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$date" missing
Loading history...
96
     * @param Environment $env
97
     * @param $date
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
98
     *
99
     * @return bool|string
100
     */
101
    public function date_day_with_weekday(Environment $env, $date)
0 ignored issues
show
Coding Style introduced by
Method name "IntlExtension::date_day_with_weekday" is not in camel caps format
Loading history...
102
    {
103
        if (!$date) {
104
            return '';
105
        }
106
107
        $date_day = \twig_localized_date_filter($env, $date, 'medium', 'none');
108
        // 曜日
109
        $dateFormatter = \IntlDateFormatter::create(
110
            'ja_JP@calendar=japanese',
111
            \IntlDateFormatter::FULL,
112
            \IntlDateFormatter::FULL,
113
            'Asia/Tokyo',
114
            \IntlDateFormatter::TRADITIONAL,
115
            'E'
116
        );
117
118
        return $date_day.'('.$dateFormatter->format($date).')';
119
    }
120
}
121