Test Setup Failed
Pull Request — master (#216)
by Viruthagiri
05:38
created

Basic_Object::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
// For adding hooks before loading WP
4
function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
5
	global $wp_filter, $merged_filters;
6
7
	$idx = _test_filter_build_unique_id($tag, $function_to_add, $priority);
8
	$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
9
	unset( $merged_filters[ $tag ] );
10
	return true;
11
}
12
13
function _test_filter_build_unique_id($tag, $function, $priority) {
0 ignored issues
show
Unused Code introduced by
The parameter $tag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $priority is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
	global $wp_filter;
15
	static $filter_id_count = 0;
16
17
	if ( is_string($function) )
18
		return $function;
19
20
	if ( is_object($function) ) {
21
		// Closures are currently implemented as objects
22
		$function = array( $function, '' );
23
	} else {
24
		$function = (array) $function;
25
	}
26
27
	if (is_object($function[0]) ) {
28
		return spl_object_hash($function[0]) . $function[1];
29
	} else if ( is_string($function[0]) ) {
30
		// Static Calling
31
		return $function[0].$function[1];
32
	}
33
}
34
35
function _delete_all_posts() {
36
	global $wpdb;
37
38
	$all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}");
39
	if ($all_posts) {
40
		foreach ($all_posts as $id)
41
			wp_delete_post( $id, true );
42
	}
43
}
44
45
class Basic_Object {
46
	private $foo = 'bar';
0 ignored issues
show
Unused Code introduced by
The property $foo is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
47
48
	public function __get( $name ) {
49
		return $this->$name;
50
	}
51
52
	public function __set( $name, $value ) {
53
		return $this->$name = $value;
54
	}
55
56
	public function __isset( $name ) {
57
		return isset( $this->$name );
58
	}
59
60
	public function __unset( $name ) {
61
		unset( $this->$name );
62
	}
63
64
	public function __call( $name, $arguments ) {
65
		return call_user_func_array( array( $this, $name ), $arguments );
66
	}
67
68
	private function callMe() {
69
		return 'maybe';
70
	}
71
}
72
73
class Basic_Subclass extends Basic_Object {}
74
75
function _wp_die_handler( $message, $title = '', $args = array() ) {
76
	if ( !$GLOBALS['_wp_die_disabled'] ) {
77
		_wp_die_handler_txt( $message, $title, $args);
78
	} else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
79
		//Ignore at our peril
80
	}
81
}
82
83
function _disable_wp_die() {
84
	$GLOBALS['_wp_die_disabled'] = true;
85
}
86
87
function _enable_wp_die() {
88
	$GLOBALS['_wp_die_disabled'] = false;
89
}
90
91
function _wp_die_handler_filter() {
92
	return '_wp_die_handler';
93
}
94
95
function _wp_die_handler_txt( $message, $title, $args ) {
96
	echo "\nwp_die called\n";
97
	echo "Message : $message\n";
98
	echo "Title : $title\n";
99
	if ( ! empty( $args ) ) {
100
		echo "Args: \n";
101
		foreach( $args as $k => $v ){
102
			echo "\t $k : $v\n";
103
		}
104
	}
105
}
106
107
/**
108
 * Set a permalink structure.
109
 *
110
 * Hooked as a callback to the 'populate_options' action, we use this function to set a permalink structure during
111
 * `wp_install()`, so that WP doesn't attempt to do a time-consuming remote request.
112
 *
113
 * @since 4.2.0
114
 */
115
function _set_default_permalink_structure_for_tests() {
116
	update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
117
}
118