Completed
Pull Request — master (#534)
by mw
01:33
created

DateParser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 53
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parseDate() 0 39 8
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.1
11
 */
12
class DateParser {
13
14
	/**
15
	 * Extract a date string formatted for iCalendar from a SMWTimeValue object.
16
	 *
17
	 * @since 3.1
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
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