AdminerTranslation   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
B _translate() 0 19 6
A tableName() 0 3 1
A fieldName() 0 3 1
A editVal() 0 5 2
1
<?php
2
/* Requires this table:
3
CREATE TABLE translation (
4
	id int NOT NULL AUTO_INCREMENT, -- optional
5
	language_id varchar(5) NOT NULL,
6
	idf text NOT NULL COLLATE utf8_bin,
7
	translation text NOT NULL,
8
	UNIQUE (language_id, idf(100)),
9
	PRIMARY KEY (id)
10
);
11
*/
12
13
/** Translate all table and field comments, enum and set values from the translation table (inserts new translations)
14
* @link https://www.adminer.org/plugins/#use
15
* @author Jakub Vrana, http://www.vrana.cz/
16
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
17
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
18
*/
19
class AdminerTranslation {
20
	
21
	function _translate($idf) {
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...
22
		static $translations, $lang;
23
		if ($lang === null) {
24
			$lang = get_lang();
25
		}
26
		if ($idf == '' || $lang == 'en') {
27
			return $idf;
28
		}
29
		if ($translations === null) {
30
			$translations = get_key_vals('SELECT idf, translation FROM translation WHERE language_id = ' . q($lang));
31
		}
32
		$return = &$translations[$idf];
33
		if ($return === null) {
34
			$return = $idf;
35
			$connection = connection();
36
			$connection->query('INSERT INTO translation (language_id, idf, translation) VALUES (' . q($lang) . ', ' . q($idf) . ', ' . q($idf) . ')');
37
		}
38
		return $return;
39
	}
40
	
41
	function tableName(&$tableStatus) {
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...
42
        $tableStatus['Comment'] = $this->_translate($tableStatus['Comment']);
43
	}
44
	
45
	function fieldName(&$field, $order = 0) {
0 ignored issues
show
Unused Code introduced by
The parameter $order 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...
46
        $field['comment'] = $this->_translate($field['comment']);
47
	}
48
	
49
	function editVal(&$val, $field) {
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...
50
		if ($field['type'] == 'enum') {
51
			$val = $this->_translate($val);
52
		}
53
	}
54
	
55
}
56