Passed
Push — fix_coverage_in_scrutinizer ( cd0379...a04ba4 )
by Herberto
13:22
created

MomentFormatConverter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 0
loc 30
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Utils;
13
14
/**
15
 * This class is used to convert PHP date format to moment.js format.
16
 *
17
 * @author Yonel Ceruto <[email protected]>
18
 */
19
class MomentFormatConverter
20
{
21
    /**
22
     * This defines the mapping between PHP ICU date format (key) and moment.js date format (value)
23
     * For ICU formats see http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax
24
     * For Moment formats see http://momentjs.com/docs/#/displaying/format/.
25
     *
26
     * @var array
27
     */
28
    private static $formatConvertRules = [
29
        // year
30
        'yyyy' => 'YYYY', 'yy' => 'YY', 'y' => 'YYYY',
31
        // day
32
        'dd' => 'DD', 'd' => 'D',
33
        // day of week
34
        'EE' => 'ddd', 'EEEEEE' => 'dd',
35
        // timezone
36
        'ZZZZZ' => 'Z', 'ZZZ' => 'ZZ',
37
        // letter 'T'
38
        '\'T\'' => 'T',
39
    ];
40
41
    /**
42
     * Returns associated moment.js format.
43
     */
44 2
    public function convert(string $format): string
45
    {
46 2
        return strtr($format, self::$formatConvertRules);
47
    }
48
}
49