Passed
Push — master ( a64e2a...e71307 )
by Dmitry
08:00
created

MonthPeriod::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 6
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-2020, 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
    public function __toString(): string
35
    {
36
        return $this->value . ' month' . ($this->value > 1 ? 's' : '');
37
    }
38
}
39