NativeHardcoded   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getNumberOrdinalSuffix() 0 7 3
A getDayShortName() 0 4 2
A getDayName() 0 4 2
A getMonthName() 0 4 2
A getMonthShortName() 0 4 2
1
<?php
2
3
namespace Popy\Calendar\Formatter\Localisation;
4
5
use Popy\Calendar\Formatter\LocalisationInterface;
6
7
/**
8
 * Hardcoded native english names, to mimic the DateTimeInterface::format
9
 * behaviour.
10
 */
11
class NativeHardcoded implements LocalisationInterface
12
{
13
    /**
14
     * Monthes names.
15
     *
16
     * @var array<string>
17
     */
18
    protected static $monthes = [
19
        'January',
20
        'February',
21
        'March',
22
        'April',
23
        'May',
24
        'June',
25
        'July',
26
        'August',
27
        'September',
28
        'October',
29
        'November',
30
        'December',
31
    ];
32
33
    /**
34
     * Week days names.
35
     *
36
     * @var array<string>
37
     */
38
    protected static $days = [
39
        'Monday',
40
        'Tuesday',
41
        'Wednesday',
42
        'Thursday',
43
        'Friday',
44
        'Saturday',
45
        'Sunday',
46
    ];
47
48
    /**
49
     * Ordinal labels.
50
     *
51
     * @var array<string>
52
     */
53
    protected static $ordinal = [
54
        'st',
55
        'nd',
56
        'rd',
57
        'th',
58
    ];
59
60
    /**
61
     * @inheritDoc
62
     */
63
    public function getMonthName($month)
64
    {
65
        if (isset(static::$monthes[$month])) {
66
            return static::$monthes[$month];
67
        }
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73
    public function getMonthShortName($month)
74
    {
75
        if (isset(static::$monthes[$month])) {
76
            return substr(static::$monthes[$month], 0, 3);
77
        }
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    public function getDayName($day)
84
    {
85
        if (isset(static::$days[$day])) {
86
            return static::$days[$day];
87
        }
88
    }
89
90
91
    /**
92
     * @inheritDoc
93
     */
94
    public function getDayShortName($day)
95
    {
96
        if (isset(static::$days[$day])) {
97
            return substr(static::$days[$day], 0, 3);
98
        }
99
    }
100
101
    /**
102
     * @inheritDoc
103
     */
104
    public function getNumberOrdinalSuffix($number)
105
    {
106
        if (isset(static::$ordinal[$number])) {
107
            return static::$ordinal[$number];
108
        }
109
110
        return end(static::$ordinal) ?: null;
111
    }
112
}
113