Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
92.31% covered (success)
92.31%
12 / 13
StandardDateSolar
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
7.02
92.31% covered (success)
92.31%
12 / 13
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 formatSymbol
0.00% covered (danger)
0.00%
0 / 1
6.03
90.91% covered (success)
90.91%
10 / 11
<?php
namespace Popy\Calendar\Formatter\SymbolFormatter;
use Popy\Calendar\FormatterInterface;
use Popy\Calendar\Parser\FormatToken;
use Popy\Calendar\Formatter\SymbolFormatterInterface;
use Popy\Calendar\Formatter\NumberConverterInterface;
use Popy\Calendar\ValueObject\DateRepresentationInterface;
use Popy\Calendar\ValueObject\DateSolarRepresentationInterface;
/**
 * Standard format, handling DateSolarRepresentationInterface.
 */
class StandardDateSolar implements SymbolFormatterInterface
{
    /**
     * Number converter.
     *
     * @var NumberConverterInterface
     */
    protected $converter;
    /**
     * Class constructor.
     *
     * @param NumberConverterInterface $converter Number converter.]
     */
    public function __construct(NumberConverterInterface $converter)
    {
        $this->converter = $converter;
    }
    /**
     * @inheritDoc
     */
    public function formatSymbol(DateRepresentationInterface $input, FormatToken $token, FormatterInterface $formatter)
    {
        if (!$input instanceof DateSolarRepresentationInterface) {
            return;
        }
        if ($token->is('y')) {
            // y   A two digit representation of a year
            return $this->converter->to($input->getYear());
        }
        if ($token->is('Y')) {
            // Y   A full numeric representation of a year, 4 digits
            return sprintf('%04d', $input->getYear());
        }
        if ($token->is('L')) {
            // L   Whether it's a leap year
            return (string)(int)$input->isLeapYear();
        }
        if ($token->is('z')) {
            // z   The day of the year (starting from 0)
            return (string)$input->getDayIndex();
        }
    }
}