Completed
Pull Request — master (#76)
by adev
03:40
created

CookieUtil   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseDate() 0 10 3
1
<?php
2
3
namespace Http\Message;
4
5
final class CookieUtil
6
{
7
    /**
8
     * Handles dates as defined by RFC 2616 section 3.3.1, and also some other
9
     * non-standard, but common formats.
10
     *
11
     * @var array
12
     */
13
    private static $dateFormats = [
14
        'D, d M y H:i:s T',
15
        'D, d M Y H:i:s T',
16
        'D, d-M-y H:i:s T',
17
        'D, d-M-Y H:i:s T',
18
        'D, d-m-y H:i:s T',
19
        'D, d-m-Y H:i:s T',
20
        'D M j G:i:s Y',
21
        'D M d H:i:s Y T',
22
    ];
23
24
    /**
25
     * @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/BrowserKit/Cookie.php
26
     *
27
     * @param string $dateValue
28
     *
29
     * @return \DateTime|false
30
     */
31 13
    public static function parseDate($dateValue)
32
    {
33 13
        foreach (self::$dateFormats as $dateFormat) {
34 13
            if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
35 10
                return $date;
36
            }
37 11
        }
38
        // attempt a fallback for unusual formatting
39 3
        return date_create($dateValue, new \DateTimeZone('GMT'));
40
    }
41
}
42