Completed
Push — master ( fc4ead...c5d222 )
by Andrii
05:51
created

MonthPeriod::addTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge\modifiers\addons;
12
13
use DateTimeImmutable;
14
15
/**
16
 * Month Period addon.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class MonthPeriod extends Period
21
{
22 5
    public function countPeriodsPassed(DateTimeImmutable $since, DateTimeImmutable $time): float
23
    {
24 5
        $diff = $time->diff($since);
25
26 5
        return ($diff->m + $diff->y*12) / $this->value;
27
    }
28
29
    public function addTo(DateTimeImmutable $since): DateTimeImmutable
30
    {
31
        return $since->add(new \DateInterval("P{$this->value}M"));
32
    }
33
}
34