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

DateTimeHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDate() 0 10 2
A getFormattedDate() 0 4 1
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