Completed
Pull Request — master (#76)
by adev
06:42
created

CookieUtil   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 36
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 = array(
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
     * @return \DateTime|false
29
     */
30
    public static function parseDate($dateValue)
31
    {
32
        foreach (self::$dateFormats as $dateFormat) {
33
            if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
34
                return $date;
35
            }
36
        }
37
        // attempt a fallback for unusual formatting
38
        return date_create($dateValue, new \DateTimeZone('GMT'));
39
    }
40
}
41