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

MonthPeriod   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 12
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A countPeriodsPassed() 0 5 1
A addTo() 0 3 1
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