Failed Conditions
Pull Request — master (#312)
by
unknown
02:18
created

tester.php ➔ db_test()   C

Complexity

Conditions 7
Paths 27

Size

Total Lines 51
Code Lines 28

Duplication

Lines 30
Ratio 58.82 %

Importance

Changes 0
Metric Value
cc 7
eloc 28
nc 27
nop 0
dl 30
loc 51
rs 6.9743
c 0
b 0
f 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
4
########################################################################
5
// Test function
6
// This happend once to be sure database is still full of datas
7
// to avoid errors on website
8
########################################################################
9
10
function php_test()
11
{
12
	$lock_msg = '';
13
14
	if (version_compare(phpversion(), '5.4', '<')) {
15
		$lock_msg .= "Error: Sorry, your PHP version isn't supported. Please upgrade to PHP >= 5.4<br>";
16
	}
17
18
	return $lock_msg;
19
}
20
21
function db_test()
22
{
23
	$lock_msg = '';
24
25
	$mysqli = new mysqli(SYS_DB_HOST, SYS_DB_USER, SYS_DB_PSWD, SYS_DB_NAME, SYS_DB_PORT);
26
27
	// Pokemon Test
28
    $result = $mysqli->query(req_tester_pokemon());
29
30 View Code Duplication
	if (!is_object($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
		$lock_msg .= "Error: No Pokémon database found<br>";
32
	} else {
33
		$data = $result->fetch_object();
34
		$total = $data->total;
35
36
		if ($total == 0) {
37
			$lock_msg .= "Error: No Pokémon found is your database<br>";
38
		}
39
	}
40
41
	// Gym Test
42
    $result = $mysqli->query(req_tester_gym());
43
44 View Code Duplication
	if (!is_object($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
		$lock_msg .= "Error: No Gym database found<br>";
46
	} else {
47
		$data = $result->fetch_object();
48
		$total = $data->total;
49
50
		if ($total == 0) {
51
			$lock_msg .= "Error: No Gym found is your database<br>";
52
		}
53
	}
54
55
56
	// Pokéstop Test
57
    $result = $mysqli->query(req_tester_pokestop());
58
59 View Code Duplication
	if (!is_object($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
		$lock_msg .= "Error: No Pokestop database found<br>";
61
	} else {
62
		$data = $result->fetch_object();
63
		$total = $data->total;
64
65
		if ($total == 0) {
66
			$lock_msg .= "Error: No Pokestop found in your database<br>";
67
		}
68
	}
69
70
	return $lock_msg;
71
}
72
73
function permission_test()
74
{
75
	$lock_msg = '';
76
77
	// Can we write on install and core/json folder?
78
	if (!is_writable(SYS_PATH.'/install/') || !is_writeable(SYS_PATH.'/core/json/')) {
79
		$lock_msg .= "Error: Install can not be completed!<br>
80
                              Please fix install/ and core/json/ directory rights.<br>
81
                              Apache needs write access to both directories.<br>";
82
		// This is really bad exit immediately
83
		echo $lock_msg;
84
		exit();
85
	}
86
87
	return $lock_msg;
88
}
89
90
function run_tests()
91
{
92
	// Execute tests
93
	$errors = '';
94
	$errors .= php_test();
95
	$errors .= db_test();
96
	$errors .= permission_test();
97
98
	// Write lockfile on error
99
	$lock_file = SYS_PATH.'/install/website.lock';
100
	if (file_exists($lock_file)) {
101
		// delete old lockfile
102
		unlink($lock_file);
103
	}
104
105
	// create new file if there is an error
106
	if ($errors != '') {
107
		file_put_contents($lock_file, $errors);
108
	}
109
}
110