RecurrenceId   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 3
dl 0
loc 98
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A applyTimeSettings() 0 13 3
A getDatetime() 0 4 1
A setDatetime() 0 6 1
A getRange() 0 4 1
A setRange() 0 6 1
A toLines() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal\Property\Event;
13
14
use Eluceo\iCal\ParameterBag;
15
use Eluceo\iCal\Property;
16
use Eluceo\iCal\Property\ValueInterface;
17
use Eluceo\iCal\Util\DateUtil;
18
19
/**
20
 * Implementation of Recurrence Id.
21
 *
22
 * @see https://tools.ietf.org/html/rfc5545#section-3.8.4.4
23
 */
24
class RecurrenceId extends Property
25
{
26
    /**
27
     * The effective range of recurrence instances from the instance
28
     * specified by the recurrence identifier specified by the property.
29
     */
30
    const RANGE_THISANDPRIOR = 'THISANDPRIOR';
31
    const RANGE_THISANDFUTURE = 'THISANDFUTURE';
32
33
    /**
34
     * The dateTime to identify a particular instance of a recurring event which is getting modified.
35
     *
36
     * @var \DateTimeInterface
37
     */
38
    protected $dateTime;
39
40
    /**
41
     * Specify the effective range of recurrence instances from the instance.
42
     *
43
     * @var string
44
     */
45
    protected $range;
46
47 11
    public function __construct(\DateTimeInterface $dateTime = null)
48
    {
49 11
        $this->name = 'RECURRENCE-ID';
50 11
        $this->parameterBag = new ParameterBag();
51 11
        if (isset($dateTime)) {
52 2
            $this->dateTime = $dateTime;
53
        }
54 11
    }
55
56 3
    public function applyTimeSettings($noTime = false, $useTimezone = false, $useUtc = false, $timezoneString = '')
57
    {
58 3
        $params = DateUtil::getDefaultParams($this->dateTime, $noTime, $useTimezone, $timezoneString);
59 3
        foreach ($params as $name => $value) {
60 1
            $this->parameterBag->setParam($name, $value);
61
        }
62
63 3
        if ($this->range) {
64 1
            $this->parameterBag->setParam('RANGE', $this->range);
65
        }
66
67 3
        $this->setValue(DateUtil::getDateString($this->dateTime, $noTime, $useTimezone, $useUtc));
68 3
    }
69
70
    /**
71
     * @return \DateTimeInterface
72
     */
73 2
    public function getDatetime()
74
    {
75 2
        return $this->dateTime;
76
    }
77
78
    /**
79
     * @return \Eluceo\iCal\Property\Event\RecurrenceId
80
     */
81 1
    public function setDatetime(\DateTimeInterface $dateTime)
82
    {
83 1
        $this->dateTime = $dateTime;
84
85 1
        return $this;
86
    }
87
88
    /**
89
     * @return string
90
     */
91 2
    public function getRange()
92
    {
93 2
        return $this->range;
94
    }
95
96
    /**
97
     * @param string $range
98
     *
99
     * @return \Eluceo\iCal\Property\Event\RecurrenceId
100
     */
101 2
    public function setRange($range)
102
    {
103 2
        $this->range = $range;
104
105 2
        return $this;
106
    }
107
108
    /**
109
     * Get all unfolded lines.
110
     *
111
     * @return array
112
     */
113 2
    public function toLines()
114
    {
115 2
        if (!$this->value instanceof ValueInterface) {
116 1
            throw new \Exception('The value must implement the ValueInterface. Call RecurrenceId::applyTimeSettings() before adding RecurrenceId.');
117
        } else {
118 1
            return parent::toLines();
119
        }
120
    }
121
}
122