Litteral::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Popy\Calendar\Formatter\SymbolFormatter;
4
5
use Popy\Calendar\FormatterInterface;
6
use Popy\Calendar\Parser\FormatToken;
7
use Popy\Calendar\Formatter\SymbolFormatterInterface;
8
use Popy\Calendar\ValueObject\DateRepresentationInterface;
9
10
/**
11
 * Handles Litteral tokens.
12
 */
13
class Litteral implements SymbolFormatterInterface
14
{
15
    /**
16
     * Will consider symbols (not handled by previous formatters) as litterals
17
     *
18
     * @var boolean
19
     */
20
    protected $considerSymbolsAsLitterals;
21
22
    /**
23
     * Class constructor.
24
     *
25
     * @param boolean $considerSymbolsAsLitterals
26
     */
27
    public function __construct($considerSymbolsAsLitterals = false)
28
    {
29
        $this->considerSymbolsAsLitterals = $considerSymbolsAsLitterals;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function formatSymbol(DateRepresentationInterface $input, FormatToken $token, FormatterInterface $formatter)
36
    {
37
        if (
38
            $token->isLitteral()
39
            || $this->considerSymbolsAsLitterals && $token->isSymbol()
40
        ) {
41
            return $token->getValue();
42
        }
43
    }
44
}
45