PregNativeRFC2550   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseSymbol() 0 12 2
A __construct() 0 3 1
1
<?php
2
3
namespace Popy\Calendar\Parser\SymbolParser;
4
5
use Popy\Calendar\Parser\FormatToken;
6
use Popy\Calendar\Parser\SymbolParserInterface;
7
use Popy\Calendar\Parser\FormatParserInterface;
8
use Popy\Calendar\Parser\DateLexer\PregSimple;
9
use Popy\Calendar\Formatter\NumberConverterInterface;
10
11
/**
12
 * Matches the native 'y' symbol when it contains a RFC2550 year.
13
 */
14
class PregNativeRFC2550 implements SymbolParserInterface
15
{
16
    /**
17
     * Number converter.
18
     *
19
     * @var NumberConverterInterface
20
     */
21
    protected $converter;
22
23
    /**
24
     * Class constructor.
25
     *
26
     * @param NumberConverterInterface $converter Number converter.]
27
     */
28
    public function __construct(NumberConverterInterface $converter)
29
    {
30
        $this->converter = $converter;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function parseSymbol(FormatToken $token, FormatParserInterface $parser)
37
    {
38
        if ($token->is('y')) {
39
            $converter = $this->converter;
40
            
41
            // y   A two digit representation of a year
42
            $lexer = new PregSimple($token, '[\\/*]?[!^]*[A-Z]*\d+');
43
            $lexer->setCallback(function (PregSimple $lexer, $value) use ($converter) {
44
                return $converter->from($value);
45
            });
46
47
            return $lexer;
48
        }
49
    }
50
}
51