Completed
Push — 1.x ( c7de71...29da9d )
by Markus
03:01
created

Calendar::buildPropertyBag()   D

Complexity

Conditions 11
Paths 768

Size

Total Lines 53
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 26.125

Importance

Changes 9
Bugs 1 Features 3
Metric Value
c 9
b 1
f 3
dl 0
loc 53
ccs 15
cts 30
cp 0.5
rs 4.1176
cc 11
eloc 31
nc 768
nop 0
crap 26.125

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Component;
13
14
use Eluceo\iCal\Component;
15
use Eluceo\iCal\PropertyBag;
16
17
class Calendar extends Component
18
{
19
    /**
20
     * Methods for calendar components.
21
     *
22
     * According to RFP 5545: 3.7.2. Method
23
     *
24
     * @link http://tools.ietf.org/html/rfc5545#section-3.7.2
25
     *
26
     * And then according to RFC 2446: 3 APPLICATION PROTOCOL ELEMENTS
27
     * @link https://www.ietf.org/rfc/rfc2446.txt
28
     */
29
    const METHOD_PUBLISH        = 'PUBLISH';
30
    const METHOD_REQUEST        = 'REQUEST';
31
    const METHOD_REPLY          = 'REPLY';
32
    const METHOD_ADD            = 'ADD';
33
    const METHOD_CANCEL         = 'CANCEL';
34
    const METHOD_REFRESH        = 'REFRESH';
35
    const METHOD_COUNTER        = 'COUNTER';
36
    const METHOD_DECLINECOUNTER = 'DECLINECOUNTER';
37
38
    /**
39
     * This property defines the calendar scale used for the calendar information specified in the iCalendar object.
40
     *
41
     * According to RFC 5545: 3.7.1. Calendar Scale
42
     *
43
     * @link http://tools.ietf.org/html/rfc5545#section-3.7
44
     */
45
    const CALSCALE_GREGORIAN = 'GREGORIAN';
46
47
    /**
48
     * The Product Identifier.
49
     *
50
     * According to RFC 2445: 4.7.3 Product Identifier
51
     *
52
     * This property specifies the identifier for the product that created the Calendar object.
53
     *
54
     * @link http://www.ietf.org/rfc/rfc2445.txt
55
     *
56
     * @var string
57
     */
58
    protected $prodId      = null;
59
    protected $method      = null;
60
    protected $name        = null;
61
    protected $description = null;
62
    protected $timezone    = null;
63
64
    /**
65
     * This property defines the calendar scale used for the
66
     * calendar information specified in the iCalendar object.
67
     *
68
     * Also identifies the calendar type of a non-Gregorian recurring appointment.
69
     *
70
     * @var string
71
     *
72
     * @see http://tools.ietf.org/html/rfc5545#section-3.7
73
     * @see http://msdn.microsoft.com/en-us/library/ee237520(v=exchg.80).aspx
74
     */
75
    protected $calendarScale = null;
76
77
    /**
78
     * Specifies whether or not the iCalendar file only contains one appointment.
79
     *
80
     * @var bool
81
     *
82
     * @see http://msdn.microsoft.com/en-us/library/ee203486(v=exchg.80).aspx
83
     */
84
    protected $forceInspectOrOpen = false;
85
86
    /**
87
     * Specifies a globally unique identifier for the calendar.
88
     *
89
     * @var string
90
     *
91
     * @see http://msdn.microsoft.com/en-us/library/ee179588(v=exchg.80).aspx
92
     */
93
    protected $calId = null;
94
95
    /**
96
     * Specifies a suggested iCalendar file download frequency for clients and
97
     * servers with sync capabilities.
98
     *
99
     * @var string
100
     *
101
     * @see http://msdn.microsoft.com/en-us/library/ee178699(v=exchg.80).aspx
102
     */
103
    protected $publishedTTL = 'P1W';
104
105
    /**
106
     * Specifies a color for the calendar in calendar for Apple/Outlook.
107
     *
108
     * @var string
109
     *
110
     * @see http://msdn.microsoft.com/en-us/library/ee179588(v=exchg.80).aspx
111
     */
112
    protected $calendarColor = null;
113
114 4
    public function __construct($prodId)
115
    {
116 4
        if (empty($prodId)) {
117
            throw new \UnexpectedValueException('PRODID cannot be empty');
118
        }
119
120 4
        $this->prodId = $prodId;
121 4
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126 4
    public function getType()
127
    {
128 4
        return 'VCALENDAR';
129
    }
130
131
    /**
132
     * @param $method
133
     *
134
     * @return $this
135
     */
136
    public function setMethod($method)
137
    {
138
        $this->method = $method;
139
140
        return $this;
141
    }
142
143
    /**
144
     * @param $name
145
     *
146
     * @return $this
147
     */
148
    public function setName($name)
149
    {
150
        $this->name = $name;
151
152
        return $this;
153
    }
154
155
    /**
156
     * @param $description
157
     *
158
     * @return $this
159
     */
160
    public function setDescription($description)
161
    {
162
        $this->description = $description;
163
164
        return $this;
165
    }
166
167
    /**
168
     * @param $timezone
169
     *
170
     * @return $this
171
     */
172
    public function setTimezone($timezone)
173
    {
174
        $this->timezone = $timezone;
175
176
        return $this;
177
    }
178
179
    /**
180
     * @param $calendarColor
181
     *
182
     * @return $this
183
     */
184
    public function setCalendarColor($calendarColor)
185
    {
186
        $this->calendarColor = $calendarColor;
187
188
        return $this;
189
    }
190
191
    /**
192
     * @param $calendarScale
193
     *
194
     * @return $this
195
     */
196
    public function setCalendarScale($calendarScale)
197
    {
198
        $this->calendarScale = $calendarScale;
199
200
        return $this;
201
    }
202
203
    /**
204
     * @param bool $forceInspectOrOpen
205
     *
206
     * @return $this
207
     */
208
    public function setForceInspectOrOpen($forceInspectOrOpen)
209
    {
210
        $this->forceInspectOrOpen = $forceInspectOrOpen;
211
212
        return $this;
213
    }
214
215
    /**
216
     * @param string $calId
217
     *
218
     * @return $this
219
     */
220
    public function setCalId($calId)
221
    {
222
        $this->calId = $calId;
223
224
        return $this;
225
    }
226
227
    /**
228
     * @param string $ttl
229
     *
230
     * @return $this
231
     */
232
    public function setPublishedTTL($ttl)
233
    {
234
        $this->publishedTTL = $ttl;
235
236
        return $this;
237
    }
238
239
    /**
240
     * {@inheritdoc}
241
     */
242 4
    public function buildPropertyBag()
243
    {
244 4
        $propertyBag = new PropertyBag();
245 4
        $propertyBag->set('VERSION', '2.0');
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
246 4
        $propertyBag->set('PRODID', $this->prodId);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
247
248 4
        if ($this->method) {
249
            $propertyBag->set('METHOD', $this->method);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
250
        }
251
252 4
        if ($this->calendarColor) {
253
            $propertyBag->set('X-APPLE-CALENDAR-COLOR', $this->calendarColor);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
254
            $propertyBag->set('X-OUTLOOK-COLOR', $this->calendarColor);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
255
            $propertyBag->set('X-FUNAMBOL-COLOR', $this->calendarColor);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
256
        }
257
258 4
        if ($this->calendarScale) {
259
            $propertyBag->set('CALSCALE', $this->calendarScale);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
260
            $propertyBag->set('X-MICROSOFT-CALSCALE', $this->calendarScale);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
261
        }
262
263 4
        if ($this->name) {
264
            $propertyBag->set('X-WR-CALNAME', $this->name);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
265
        }
266
267 4
        if ($this->description) {
268
            $propertyBag->set('X-WR-CALDESC', $this->description);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
269
        }
270
271 4
        if ($this->timezone) {
272
            if ($this->timezone instanceof Timezone) {
273
                $propertyBag->set('X-WR-TIMEZONE', $this->timezone->getZoneIdentifier());
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
274
                $this->addComponent($this->timezone);
275
            } else {
276
                $propertyBag->set('X-WR-TIMEZONE', $this->timezone);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
277
                $this->addComponent(new Timezone($this->timezone));
278
            }
279
        }
280
281 4
        if ($this->forceInspectOrOpen) {
282
            $propertyBag->set('X-MS-OLK-FORCEINSPECTOROPEN', $this->forceInspectOrOpen);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
283
        }
284
285 4
        if ($this->calId) {
286
            $propertyBag->set('X-WR-RELCALID', $this->calId);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
287
        }
288
289 4
        if ($this->publishedTTL) {
290 4
            $propertyBag->set('X-PUBLISHED-TTL', $this->publishedTTL);
0 ignored issues
show
Deprecated Code introduced by
The method Eluceo\iCal\PropertyBag::set() has been deprecated with message: The property bag should not be used as a property factory. Use `$this->add` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
291
        }
292
293 4
        return $propertyBag;
294
    }
295
296
    /**
297
     * @return null|string
298
     */
299
    public function getProdId()
300
    {
301
        return $this->prodId;
302
    }
303
304
    public function getMethod()
305
    {
306
        return $this->method;
307
    }
308
}
309