Completed
Push — master ( b51007...cd2f8d )
by mw
37:59 queued 02:53
created

JulianDayTest::valueProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 59
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 59
rs 9.597
c 1
b 0
f 0
cc 1
eloc 35
nc 1
nop 0

How to fix   Long Method   

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
namespace SMW\Tests;
4
5
use SMW\JulianDay;
6
use SMWDITime as DITime;
7
8
/**
9
 * @covers \SMW\JulianDay
10
 * @group semantic-mediawiki
11
 *
12
 * @license GNU GPL v2+
13
 * @since 2.4
14
 *
15
 * @author mwjames
16
 */
17
class JulianDayTest extends \PHPUnit_Framework_TestCase {
18
19
	/**
20
	 * @dataProvider valueProvider
21
	 */
22
	public function testConvert( $seralization, $jdValue ) {
23
24
		$this->assertEquals(
25
			$jdValue,
26
			JulianDay::get( DITime::doUnserialize( $seralization ) )
27
		);
28
29
		$this->assertEquals(
30
			DITime::doUnserialize( $seralization ),
31
			JulianDay::newDiFromJD( $jdValue )
32
		);
33
	}
34
35
	public function valueProvider() {
36
37
		$provider[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$provider was never initialized. Although not strictly required by PHP, it is generally a good practice to add $provider = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
38
			'2/1352/01/01',
39
			'2214875.500000'
40
		);
41
42
		$provider[] = array(
43
			'1/2100/10/04',
44
			'2488345.500000'
45
		);
46
47
		$provider[] = array(
48
			'1/2100/10/04',
49
			'2488345.500000'
50
		);
51
52
		$provider[] = array(
53
			'2/1582/10/04',
54
			'2299159.500000'
55
		);
56
57
		$provider[] = array(
58
			'1/1582/10/15',
59
			'2299160.5'
60
		);
61
62
		$provider[] = array(
63
			'2/-900/10/4',
64
			'1392974.500000'
65
		);
66
67
		$provider[] = array(
68
			'2/-4713/01/02',
69
			'0.5'
70
		);
71
72
		$provider[] = array(
73
			'2/-4713/01/02/12/0/0',
74
			'1'
75
		);
76
77
		$provider[] = array(
78
			'2/-9000/10/4',
79
			'-1565550.5'
80
		);
81
82
		$provider[] = array(
83
			'1/2100/10/4/13/55/55',
84
			'2488346.0804977'
85
		);
86
87
		$provider[] = array(
88
			'1/2100/10/4/13/55/55',
89
			2488346.0804977
90
		);
91
92
		return $provider;
93
	}
94
95
}
96