Failed Conditions
Pull Request — master (#353)
by Florian
05:07
created

tester.php ➔ db_test()   C

Complexity

Conditions 7
Paths 27

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 19
nc 27
nop 0
dl 0
loc 36
rs 6.7272
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
// Load Query Manager
4
// ###################
5
6
include_once __DIR__ . '/../core/process/queries/QueryManager.php';
7
8
9
########################################################################
10
// Test function
11
// This happend once to be sure database is still full of datas
12
// to avoid errors on website
13
########################################################################
14
15
function php_test()
16
{
17
	$lock_msg = '';
18
19
	if (version_compare(phpversion(), '5.4', '<')) {
20
		$lock_msg .= "Error: Sorry, your PHP version isn't supported. Please upgrade to PHP >= 5.4<br>";
21
	}
22
23
	return $lock_msg;
24
}
25
26
function db_test()
27
{
28
	$manager = QueryManager::current();
29
30
	$lock_msg = '';
31
32
	// Pokemon Test
33
	$result = $manager->testTotalPokemon();
34
35
	if ($result === 1) {
36
		$lock_msg .= "Error: No Pokémon database found<br>";
37
	} else if ($result === 2) {
38
		$lock_msg .= "Error: No Pokémon found is your database<br>";
39
	}
40
41
	// Gym Test
42
	$result = $manager->testTotalGyms();
43
44
	if ($result === 1) {
45
		$lock_msg .= "Error: No Gym database found<br>";
46
	} else if ($result === 2) {
47
		$lock_msg .= "Error: No Gym found is your database<br>";
48
	}
49
50
51
	// Pokéstop Test
52
	$result = $manager->testTotalPokestops();
53
54
	if ($result === 1) {
55
		$lock_msg .= "Error: No Pokestop database found<br>";
56
	} else if ($result === 2) {
57
		$lock_msg .= "Error: No Pokestop found in your database<br>";
58
	}
59
60
	return $lock_msg;
61
}
62
63
function permission_test()
64
{
65
	$lock_msg = '';
66
67
	// Can we write on install and core/json folder?
68
	if (!is_writable(SYS_PATH.'/install/') || !is_writeable(SYS_PATH.'/core/json/')) {
69
		$lock_msg .= "Error: Install can not be completed!<br>
70
                              Please fix install/ and core/json/ directory rights.<br>
71
                              Apache needs write access to both directories.<br>";
72
		// This is really bad exit immediately
73
		echo $lock_msg;
74
		exit();
75
	}
76
77
	return $lock_msg;
78
}
79
80
function run_tests()
81
{
82
	// Execute tests
83
	$errors = '';
84
	$errors .= php_test();
85
	$errors .= db_test();
86
	$errors .= permission_test();
87
88
	// Write lockfile on error
89
	$lock_file = SYS_PATH.'/install/website.lock';
90
	if (file_exists($lock_file)) {
91
		// delete old lockfile
92
		unlink($lock_file);
93
	}
94
95
	// create new file if there is an error
96
	if ($errors != '') {
97
		file_put_contents($lock_file, $errors);
98
	}
99
}
100