WonnovaDateTimeParserTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B parseWonnovaDateTime() 0 16 6
1
<?php
2
namespace Wonnova\SDK\Common;
3
4
/**
5
 * This provides a common method for all the objects to parse inconsistent serialized dates into DateTime objects
6
 * @author
7
 * @link
8
 */
9
trait WonnovaDateTimeParserTrait
10
{
11
    /**
12
     * Parses a date serialized as string, array or DateTime object itself
13
     *
14
     * @param array|string|\DateTime $data
15
     * @return \DateTime|null
16
     */
17 24
    protected function parseWonnovaDateTime($data)
18
    {
19 24
        if (is_array($data)) {
20 8
            $formatedDate = isset($data['date']) ? $data['date'] : 'now';
21 8
            $timezone = isset($data['timezone']) ? new \DateTimeZone($data['timezone']) : null;
22 8
            $dateTime = new \DateTime($formatedDate, $timezone);
23
24 8
            return $dateTime;
25 18
        } elseif (is_string($data)) {
26 15
            return new \DateTime($data);
27 8
        } elseif ($data instanceof \DateTime) {
28 7
            return $data;
29
        }
30
31 1
        return null;
32
    }
33
}
34