Completed
Pull Request — master (#33)
by Rafał
09:16
created

DateTimeHelper::getDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\SubscriptionBundle\Helper;
6
7
final class DateTimeHelper implements DateTimeHelperInterface
8
{
9
    /**
10
     * @inheritdoc}
11
     */
12
    public function getDate(int $day, int $months = 0): \DateTimeInterface
13
    {
14
        $date = new \DateTime(date('Y-m-'.$day));
15
16
        if (0 !== $months) {
17
            $date->modify(sprintf('+%d months', $months));
18
        }
19
20
        return $date;
21
    }
22
23
    /**
24
     * @inheritdoc}
25
     */
26
    public function getFormattedDate(int $day, int $months = 0, $format = 'Y-m-d'): string
27
    {
28
        return $this->getDate($day, $months)->format($format);
29
    }
30
}
31