1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* qa.variables.inc |
6
|
|
|
* |
7
|
|
|
* @author: Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @copyright (c) 2014 Ouest Systèmes Informatiques (OSInet). |
10
|
|
|
* |
11
|
|
|
* @license General Public License version 2 or later |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use Drupal\qa\Plugin\Qa\Control\Variable\Variable; |
15
|
|
|
|
16
|
|
|
function qa_report_variable(Variable $variable = NULL) { |
17
|
|
|
$bc = drupal_get_breadcrumb(); |
18
|
|
|
$bc[] = l(t('Administration'), 'admin'); |
19
|
|
|
$bc[] = l(t('Reports'), 'admin/reports'); |
20
|
|
|
$bc[] = l(t('Quality Assurance'), 'admin/reports/qa'); |
21
|
|
|
$bc[] = l(t('Variables'), 'admin/reports/qa/variable'); |
22
|
|
|
drupal_set_breadcrumb($bc); |
23
|
|
|
|
24
|
|
|
drupal_set_title(t('Variable: %name', array('%name' => $variable->name)), PASS_THROUGH); |
25
|
|
|
return $variable->dump(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function _qa_compare_variables($x, $y) { |
29
|
|
|
if ($x[1] < $y[1]) { |
30
|
|
|
$ret = -1; |
31
|
|
|
} elseif ($x[1] > $y[1]) { |
32
|
|
|
$ret = 1; |
33
|
|
|
} else { |
34
|
|
|
$ret = strcmp($x[0], $y[0]); |
35
|
|
|
} |
36
|
|
|
//echo "comparing" . print_r($x, true) . " / " . print_r($y, true) . ": " . -$ret . "\n"; |
37
|
|
|
return - $ret; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Page callback for variables list. |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
function qa_report_variables() { |
46
|
|
|
$cached = cache_get('variables', 'cache_bootstrap'); |
47
|
|
|
if ($cached === FALSE) { |
48
|
|
|
$cached = (object) array( |
49
|
|
|
'data' => array(), |
50
|
|
|
'serialized' => FALSE, |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$header = array( |
55
|
|
|
t('Name'), |
56
|
|
|
t('Length'), |
57
|
|
|
t('Value, or size for arrays'), |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$rows = array(); |
61
|
|
|
foreach ($cached->data as $name => $value) { |
62
|
|
|
$row = array(); |
63
|
|
|
$variable = new Variable($name); |
64
|
|
|
$row[] = $variable->link(); |
65
|
|
|
$row[] = is_scalar($value) ? strlen($value) : strlen(serialize($value)); |
66
|
|
|
|
67
|
|
View Code Duplication |
if (is_array($value)) { |
|
|
|
|
68
|
|
|
$cell = t("Array[@count]", array('@count' => count($value))); |
69
|
|
|
} else { |
70
|
|
|
$raw = is_string($value) ? $value : serialize($value); |
71
|
|
|
$raw = check_plain($raw); |
72
|
|
|
$cell = (strlen($raw) > 200) ? substr($raw, 0, 200) . '…' : $raw; |
73
|
|
|
} |
74
|
|
|
$row[] = $cell; |
75
|
|
|
$rows[] = $row; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
usort($rows, _qa_compare_variables::class); |
79
|
|
|
return theme('table', array( |
80
|
|
|
'header' => $header, |
81
|
|
|
'rows' => $rows, |
82
|
|
|
)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
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.