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
72.73% covered (warning)
72.73%
8 / 11
FloatBased
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
3.18
72.73% covered (warning)
72.73%
8 / 11
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 isLeapYear
0.00% covered (danger)
0.00%
0 / 1
2.31
57.14% covered (warning)
57.14%
4 / 7
<?php
namespace Popy\Calendar\Converter\LeapYearCalculator;
use Popy\Calendar\Converter\SimpleLeapYearCalculatorInterface;
/**
 * Float based calculator.
 */
class FloatBased implements SimpleLeapYearCalculatorInterface
{
    /**
     * Remaining day part at the end of a regular year.
     *
     * @var string|float
     */
    protected $remaining;
    /**
     * Class constructor.
     *
     * @param float $yearLengthInDays Year length.
     */
    public function __construct($yearLengthInDays)
    {
        $diff = explode('.', $yearLengthInDays);
        $diff[0] = '0';
        $this->remaining = implode('.', $diff);
    }
    /**
     * @inheritDoc
     */
    public function isLeapYear($year)
    {
        if (function_exists('bcmul')) {
            return
                floor((float)bcmul($year - 1, $this->remaining))
                < floor((float)bcmul($year, $this->remaining))
            ;
        }
        return
            floor(($year - 1) * (float)$this->remaining)
            < floor($year * (float)$this->remaining)
        ;
    }
}