DateTimeFormater   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 4 1
A formatDateTime() 0 7 2
1
<?php
2
3
/**
4
 * Copyright (c) 2017 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of ci-report.
7
 *
8
 * ci-report is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * ci-report is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace App\Twig;
24
25
use DateTime;
26
use Twig_Extension;
27
use Twig_SimpleFunction;
28
29
/**
30
 * DateTime formater class Twig extension.
31
 *
32
 * @category  ci-report app
33
 *
34
 * @author    Francois-Xavier Soubirou <[email protected]>
35
 * @copyright 2017 Francois-Xavier Soubirou
36
 * @license   http://www.gnu.org/licenses/   GPLv3
37
 *
38
 * @see      https://www.ci-report.io
39
 */
40
class DateTimeFormater extends Twig_Extension
41
{
42
    /**
43
     * Returns a list of functions to add to the existing list.
44
     *
45
     * @return array
46
     */
47
    public function getFunctions(): array
48
    {
49
        return array(
50
            new Twig_SimpleFunction('datetimeFormat', array($this, 'formatDateTime')),
51
        );
52
    }
53
54
    /**
55
     * Return formated datetime.
56
     *
57
     * @param DateTime $datetime DateTime object
58
     *
59
     * @return string
60
     */
61
    public function formatDateTime(?DateTime $datetime): string
62
    {
63
        if (null === $datetime) {
64
            return '-';
65
        }
66
67
        return $datetime->format('d/m/Y H:i:s');
68
    }
69
}
70