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

DateTimeHelper::getFormattedDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
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