Completed
Push — master ( b4ec31...132ebc )
by Mark van den
11:12
created

PostmarkDate::getAbbreviatedDays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Mvdnbrk\Postmark\Support;
4
5
use DateTime;
6
use Mvdnbrk\Postmark\Support\Collection;
7
8
class PostmarkDate extends DateTime
9
{
10
    /**
11
     *  Constants for numeric representation of the day of the week.
12
     */
13
    const SUNDAY = 0;
14
    const MONDAY = 1;
15
    const TUESDAY = 2;
16
    const WEDNESDAY = 3;
17
    const THURSDAY = 4;
18
    const FRIDAY = 5;
19
    const SATURDAY = 6;
20
21
    /**
22
     * Textual representation of a day, three letters.
23
     *
24
     * @var array
25
     */
26
    protected static $days_abbreviated = [
27
        self::SUNDAY => 'Sun',
28
        self::MONDAY => 'Mon',
29
        self::TUESDAY => 'Tue',
30
        self::WEDNESDAY => 'Wed',
31
        self::THURSDAY => 'Thu',
32
        self::FRIDAY => 'Fri',
33
        self::SATURDAY => 'Sat',
34
    ];
35
36
    /**
37
     * Get the textual respresentation of a day as three letters.
38
     *
39
     * @return array
40
     */
41
    public static function getAbbreviatedDays()
42
    {
43
        return static::$days_abbreviated;
44
    }
45
46
    /**
47
     * Get a collection of the textual respresentation of a day as three letters.
48
     *
49
     * @return \Mvdnbrk\Postmark\Support\Collection
50
     */
51
    public static function getAbbreviatedDaysCollection()
52
    {
53
        return new Collection(static::getAbbreviatedDays());
54
    }
55
56
    /**
57
     * Set the instance to UTC timezone.
58
     *
59
     * @return static
60
     */
61
    public function inUtcTimezone()
62
    {
63
        return parent::setTimezone(timezone_open('UTC'));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setTimezone() instead of inUtcTimezone()). Are you sure this is correct? If so, you might want to change this to $this->setTimezone().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64
    }
65
66
    /**
67
     * Created a new instance from a string.
68
     *
69
     * @param  string $date
70
     * @return static
71
     */
72
    public static function parse($date)
73
    {
74
        $date = new Collection(explode(' ', $date));
75
76
        return new static($date->reject(function ($value) {
77
                return self::getAbbreviatedDaysCollection()->contains(trim($value, ','));
78
        })
79
            ->take(5)
80
            ->implode(' '));
81
    }
82
83
    /**
84
     * Dynamically retrieve attributes on the data model.
85
     *
86
     * @param  string  $key
87
     * @throws \InvalidArgumentException
88
     * @return mixed
89
     */
90
    public function __get($key)
91
    {
92
        switch (true) {
93
            case $key === 'isUtc':
94
                return $this->getOffset() === 0;
95
            case $key === 'timezone':
96
                return $this->getTimezone()->getName();
97
            default:
98
                throw new \InvalidArgumentException(sprintf("Unknown getter '%s'", $key));
99
        }
100
    }
101
}
102