Completed
Branch master (0fc797)
by Michael
13:18 queued 09:16
created

AdminerDumpJson   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 13
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A dumpFormat() 0 3 1
A dumpTable() 0 5 2
A _database() 0 3 1
C dumpData() 0 27 7
A dumpHeaders() 0 6 2
1
<?php
2
3
/** Dump to JSON format
4
* @link https://www.adminer.org/plugins/#use
5
* @author Jakub Vrana, http://www.vrana.cz/
6
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
7
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
8
*/
9
class AdminerDumpJson {
10
	/** @access protected */
11
	var $database = false;
12
	
13
	function dumpFormat() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
		return array('json' => 'JSON');
15
	}
16
17
	function dumpTable($table, $style, $is_view = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $table 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 $style 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 $is_view 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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18
		if ($_POST['format'] == 'json') {
19
			return true;
20
		}
21
	}
22
	
23
	function _database() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
		echo "}\n";
25
	}
26
	
27
	function dumpData($table, $style, $query) {
0 ignored issues
show
Unused Code introduced by
The parameter $style 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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
		if ($_POST['format'] == 'json') {
29
			if ($this->database) {
30
				echo ",\n";
31
			} else {
32
				$this->database = true;
33
				echo "{\n";
34
				register_shutdown_function(array($this, '_database'));
35
			}
36
			$connection = connection();
37
			$result = $connection->query($query, 1);
38
			if ($result) {
39
				echo '"' . addcslashes($table, "\r\n\"\\") . "\": [\n";
40
				$first = true;
41
				while ($row = $result->fetch_assoc()) {
42
					echo ($first ? '' : ', ');
43
					$first = false;
44
					foreach ($row as $key => $val) {
45
						json_row($key, $val);
46
					}
47
					json_row('');
48
				}
49
				echo ']';
50
			}
51
			return true;
52
		}
53
	}
54
55
	function dumpHeaders($identifier, $multi_table = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $identifier 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 $multi_table 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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
		if ($_POST['format'] == 'json') {
57
			header('Content-Type: application/json; charset=utf-8');
58
			return 'json';
59
		}
60
	}
61
62
}
63