Completed
Push — master ( 823f1c...5ca85f )
by Rafał
08:28
created

StartDateProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 19.35 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 6
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getStartDates() 6 18 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\SubscriptionBundle\Provider;
6
7
use PH\Bundle\SubscriptionBundle\Helper\DateTimeHelperInterface;
8
9
final class StartDateProvider implements StartDateProviderInterface
10
{
11
    private $dateTimeHelper;
12
13
    public function __construct(DateTimeHelperInterface $dateTimeHelper)
14
    {
15
        $this->dateTimeHelper = $dateTimeHelper;
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getStartDates(): array
22
    {
23
        $now = $this->dateTimeHelper->getCurrentDateTime();
24
        $dates = [];
25
26 View Code Duplication
        if ($now < $this->dateTimeHelper->getDate(1)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
            $dates[$this->dateTimeHelper->getFormattedDate(1)] = $this->dateTimeHelper->getFormattedDate(1);
28
        }
29
30 View Code Duplication
        if ($now < $this->dateTimeHelper->getDate(15)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
            $dates[$this->dateTimeHelper->getFormattedDate(15)] = $this->dateTimeHelper->getFormattedDate(15);
32
        }
33
34
        return array_merge($dates, [
35
            $this->dateTimeHelper->getFormattedDate(1, 1) => $this->dateTimeHelper->getFormattedDate(1, 1),
36
            $this->dateTimeHelper->getFormattedDate(15, 1) => $this->dateTimeHelper->getFormattedDate(15, 1),
37
        ]);
38
    }
39
}
40