Holiday::setType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Holiday Library.
5
 *
6
 * (c) Michał Mańko <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Michalmanko\Holiday;
13
14
use DateTime;
15
use DateTimeZone;
16
17
/**
18
 * Holiday class.
19
 *
20
 * @author Michał Mańko <[email protected]>
21
 */
22
class Holiday extends DateTime
23
{
24
    /**
25
     * Holiday type - Holiday.
26
     */
27
    const TYPE_HOLIDAY = 'holiday';
28
29
    /**
30
     * Holiday type - School Holiday.
31
     */
32
    const TYPE_SCHOOL_HOLIDAY = 'school';
33
34
    /**
35
     * Holiday type - notable.
36
     */
37
    const TYPE_NOTABLE = 'notable';
38
39
    /**
40
     * Holiday type.
41
     *
42
     * @var string
43
     */
44
    private $type;
45
46
    /**
47
     * Holiday name.
48
     *
49
     * @var string
50
     */
51
    private $name;
52
53
    /**
54
     * Creates a new Holiday.
55
     *
56
     * @param string            $name     Name
57
     * @param mixed             $time     Time
58
     * @param null|DateTimeZone $timezone (optional) Timezone
59
     * @param null|string       $type     (optional) Type
60
     */
61 47
    public function __construct(
62
        $name,
63
        $time,
64
        DateTimeZone $timezone = null,
65
        $type = self::TYPE_HOLIDAY
66
    ) {
67 47
        if ($time instanceof DateTime) {
68 26
            $time = $time->format('Y-m-d H:i:s');
69 26
        }
70 47
        parent::__construct($time, $timezone);
71
72 47
        $this->setName($name);
73 47
        $this->setType($type);
74 47
    }
75
76
    /**
77
     * Returns the holiday name.
78
     *
79
     * @return string
80
     */
81 27
    public function getName()
82
    {
83 27
        return $this->name;
84
    }
85
86
    /**
87
     * Sets the holiday name.
88
     *
89
     * @param string $name
90
     *
91
     * @return Holiday
92
     */
93 47
    public function setName($name)
94
    {
95 47
        $this->name = $name;
96
97 47
        return $this;
98
    }
99
100
    /**
101
     * Returns the holiday type.
102
     *
103
     * @return string
104
     */
105 31
    public function getType()
106
    {
107 31
        return $this->type;
108
    }
109
110
    /**
111
     * Sets the holiday type.
112
     *
113
     * @param string $type
114
     *
115
     * @return Holiday
116
     */
117 47
    public function setType($type)
118
    {
119 47
        $this->type = $type;
120
121 47
        return $this;
122
    }
123
}
124