MonthList::forge()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
namespace Tuum\Form\Lists;
3
4
use Closure;
5
6
class MonthList extends AbstractList
7
{
8
    /**
9
     * @param null|int $start
10
     * @param null|int $end
11
     * @param int      $step
12
     * @return MonthList|static
13
     */
14
    public static function forge($start = 1, $end = 12, $step = 1)
15
    {
16
        return new self(
17
            $start,
18
            $end,
19
            $step,
20
            function ($month) {
21
                return sprintf('%2d', $month);
22
            });
23
    }
24
25
    /**
26
     * uses full-text of month name, like 'January'.
27
     *
28
     * @return $this
29
     */
30
    public function useFullText()
31
    {
32
        return $this->setFormat(self::formatFullText());
33
    }
34
35
    /**
36
     * @return Closure
37
     */
38
    public static function formatFullText()
39
    {
40
        return function ($m) {
41
            $list = [
42
                'January',
43
                'February',
44
                'March',
45
                'April',
46
                'May',
47
                'June',
48
                'July',
49
                'August',
50
                'September',
51
                'October',
52
                'November',
53
                'December'
54
            ];
55
            return $list[--$m];
56
        };
57
    }
58
}
59