PresetParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 3 1
1
<?php
2
3
namespace Popy\Calendar;
4
5
use DateTimeInterface;
6
7
/**
8
 * Utility/Helper class : Stores a preset date formatting to be used as a quick parser.
9
 */
10
class PresetParser
11
{
12
    /**
13
     * Parser.
14
     *
15
     * @var ParserInterface
16
     */
17
    protected $parser;
18
19
    /**
20
     * Preset format.
21
     *
22
     * @var string
23
     */
24
    protected $format;
25
26
    /**
27
     * Class constructor.
28
     *
29
     * @param ParserInterface $parser parser
30
     * @param string          $format   Date format
31
     */
32
    public function __construct(ParserInterface $parser, $format)
33
    {
34
        $this->parser = $parser;
35
        $this->format = $format;
36
    }
37
38
    /**
39
     * Parses the input string into a date.
40
     *
41
     * @param string $input
42
     *
43
     * @return DateTimeInterface|null
44
     */
45
    public function parse($input)
46
    {
47
        return $this->parser->parse($input, $this->format);
48
    }
49
}
50