Completed
Push — master ( ee3f46...2dd99c )
by Markus
03:13
created

DateTimesProperty::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 2
eloc 11
nc 2
nop 5
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;
13
14
use Eluceo\iCal\Property;
15
use Eluceo\iCal\Util\DateUtil;
16
17
class DateTimesProperty extends Property
18
{
19
    /**
20
     * @param string      $name
21
     * @param \DateTime[] $dateTimes
22
     * @param bool        $noTime
23
     * @param bool        $useTimezone
24
     * @param bool        $useUtc
25
     */
26
    public function __construct(
27
        $name,
28
        $dateTimes = array(),
29
        $noTime = false,
30
        $useTimezone = false,
31
        $useUtc = false
32
    ) {
33
        $dates = array();
34
        foreach ($dateTimes as $dateTime) {
35
            $dates[] = DateUtil::getDateString($dateTime, $noTime, $useTimezone, $useUtc);
36
        }
37
        $params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone);
0 ignored issues
show
Bug introduced by
The variable $dateTime seems to be defined by a foreach iteration on line 34. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
38
39
        parent::__construct($name, $dates, $params);
40
    }
41
}
42