Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
CRAP
88.89% covered (warning)
88.89%
8 / 9
StandardDateSolar
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
2 / 3
5.03
88.89% covered (warning)
88.89%
8 / 9
 map
0.00% covered (danger)
0.00%
0 / 1
2.03
80.00% covered (warning)
80.00%
4 / 5
 determineYear
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 determineDayIndex
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
<?php
namespace Popy\Calendar\Parser\ResultMapper;
use Popy\Calendar\Parser\DateLexerResult;
use Popy\Calendar\Parser\ResultMapperInterface;
use Popy\Calendar\ValueObject\DateRepresentationInterface;
use Popy\Calendar\ValueObject\DateSolarRepresentationInterface;
/**
 * Maps standard format year symbols to DateSolarRepresentationInterface fields.
 */
class StandardDateSolar implements ResultMapperInterface
{
    /**
     * @inheritDoc
     */
    public function map(DateLexerResult $parts, DateRepresentationInterface $date)
    {
        if (!$date instanceof DateSolarRepresentationInterface) {
            return;
        }
        return $date
            ->withYear($this->determineYear($parts), $parts->get('L'))
            ->withDayIndex($this->determineDayIndex($parts), null)
        ;
    }
    /**
     * Determine year.
     *
     * @param DateLexerResult $parts
     *
     * @return integer|null
     */
    protected function determineYear(DateLexerResult $parts)
    {
        // Assumes 'y' is properly handled in lexer
        return $parts->getFirst('Y', 'y');
    }
    /**
     * Determine year.
     *
     * @param DateLexerResult $parts
     *
     * @return integer|null
     */
    protected function determineDayIndex(DateLexerResult $parts)
    {
        // z   The day of the year (starting from 0)
        if (null !== $z = $parts->get('z')) {
            return (int)$z;
        }
    }
}