YearPeriod   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addTo() 0 3 1
A countPeriodsPassed() 0 5 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-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\charge\modifiers\addons;
12
13
use DateTimeImmutable;
14
15
/**
16
 * Year Period addon.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class YearPeriod extends Period
21
{
22
    public function countPeriodsPassed(DateTimeImmutable $since, DateTimeImmutable $time): float
23
    {
24
        $diff = $time->diff($since);
25
26
        return $diff->y / $this->value;
27
    }
28
29
    public function addTo(DateTimeImmutable $since): DateTimeImmutable
30
    {
31
        return $since->add(new \DateInterval("P{$this->value}Y"));
32
    }
33
}
34