Completed
Pull Request — master (#41)
by Guillaume
03:05
created

DateValidation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 68.42 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 26
loc 38
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isDateValid() 13 13 3
A isDateTimeValid() 13 13 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
declare(strict_types = 1);
3
4
namespace Imedia\Ammit\Domain;
5
6
/**
7
 * @author Guillaume MOREL <[email protected]>
8
 */
9
class DateValidation
10
{
11
    const FORMAT_SIMPLE = 'Y-m-d';
12
    const FORMAT_RFC3339 = \DateTime::RFC3339;
13
14
    /**
15
     * Valid against Y-m-d format
16
     * @param string $dateString String to validate
17
     * @return bool
18
     */
19 View Code Duplication
    public function isDateValid(string $dateString): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
20
    {
21 1
        $date = \DateTime::createFromFormat(self::FORMAT_SIMPLE, $dateString);
22 1
        if (false === $date) {
23 1
            return false;
24
        }
25
26 1
        if ($date->format(self::FORMAT_SIMPLE) === $dateString) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $date->format(sel...IMPLE) === $dateString;.
Loading history...
27 1
            return true;
28
        }
29
30 1
        return false;
31
    }
32
33 View Code Duplication
    public function isDateTimeValid(string $dateString): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
34
    {
35 1
        $date = \DateTime::createFromFormat(self::FORMAT_RFC3339, $dateString);
36 1
        if (false === $date) {
37 1
            return false;
38
        }
39
40 1
        if ($date->format(self::FORMAT_RFC3339) === $dateString) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $date->format(sel...C3339) === $dateString;.
Loading history...
41 1
            return true;
42
        }
43
44 1
        return false;
45
    }
46
}
47