Test Failed
Push — master ( abf703...9671b2 )
by Jonathan
04:24 queued 01:11
created

ActionScheduler_UnitTestCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 39
loc 39
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Class ActionScheduler_UnitTestCase
5
 */
6
class ActionScheduler_UnitTestCase extends WP_UnitTestCase {
7
8
	protected $existing_timezone;
9
10
	/**
11
	 * Counts the number of test cases executed by run(TestResult result).
12
	 *
13
	 * @return int
14
	 */
15
	public function count() {
16
		return 'UTC' == date_default_timezone_get() ? 2 : 3;
17
	}
18
19
	/**
20
	 * We want to run every test multiple times using a different timezone to make sure
21
	 * that they are unaffected by changes to PHP's timezone.
22
	 */
23
	public function run( PHPUnit\Framework\TestResult $result = NULL ){
24
25
		if ($result === NULL) {
26
			$result = $this->createResult();
27
		}
28
29
		if ( 'UTC' != ( $this->existing_timezone = date_default_timezone_get() ) ) {
30
			date_default_timezone_set( 'UTC' );
31
			$result->run( $this );
32
		}
33
34
		date_default_timezone_set( 'Pacific/Fiji' ); // UTC+12
35
		$result->run( $this );
36
37
		date_default_timezone_set( 'Pacific/Tahiti' ); // UTC-10: it's a magical place
38
		$result->run( $this );
39
40
		date_default_timezone_set( $this->existing_timezone );
41
42
		return $result;
43
	}
44
}
45