DateParser::parseDate()   B
last analyzed

Complexity

Conditions 8
Paths 17

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 8.0079

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 19
cts 20
cp 0.95
rs 8.0515
c 0
b 0
f 0
cc 8
nc 17
nop 2
crap 8.0079
1
<?php
2
3
namespace SRF\iCalendar;
4
5
use SMWDataValueFactory as DataValueFactory;
6
use SMWTimeValue as TimeValue;
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 3.2
11
 */
12
class DateParser {
13
14
	/**
15
	 * Extract a date string formatted for iCalendar from a SMWTimeValue object.
16
	 *
17
	 * @since 3.2
18
	 *
19
	 * @param TimeValue $dataValue
20
	 * @param boolean $isEnd
21
	 *
22
	 * @return string
23
	 */
24 4
	public function parseDate( TimeValue $dataValue, $isEnd = false ) {
25 4
		$year = $dataValue->getYear();
26
27
		// ISO range is limited to four digits
28 4
		if ( ( $year > 9999 ) || ( $year < -9998 ) ) {
29
			return '';
30
		}
31
32 4
		$year = number_format( $year, 0, '.', '' );
33 4
		$time = str_replace( ':', '', $dataValue->getTimeString( false ) );
0 ignored issues
show
Documentation introduced by Jeroen De Dauw
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
35
		// increment by one day, compute date to cover leap years etc.
36 4
		if ( ( $time == false ) && ( $isEnd ) ) {
37 1
			$dataValue = DataValueFactory::getInstance()->newDataValueByType(
38 1
				'_dat',
39 1
				$dataValue->getWikiValue() . 'T00:00:00-24:00'
40
			);
41
		}
42
43 4
		$month = $dataValue->getMonth();
44
45 4
		if ( strlen( $month ) == 1 ) {
46 3
			$month = '0' . $month;
47
		}
48
49 4
		$day = $dataValue->getDay();
50
51 4
		if ( strlen( $day ) == 1 ) {
52 3
			$day = '0' . $day;
53
		}
54
55 4
		$result = $year . $month . $day;
56
57 4
		if ( $time != false ) {
58 3
			$result .= "T$time";
59
		}
60
61 4
		return $result;
62
	}
63
64
}
65