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

DateValidation::isDateTimeValid()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3
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