Skip to content

Commit 4dc620a

Browse files
committed
short arrays
1 parent fecad55 commit 4dc620a

15 files changed

+274
-281
lines changed

front/object.form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
$types = array_keys(PluginGenericobjectType::getTypes());
3737

3838
$requested_type = $_REQUEST['itemtype'];
39-
$error = array();
39+
$error = [];
4040

4141
if (!in_array($requested_type, $types)) {
4242
$error[] = __('The requested type has not been defined yet!');
@@ -101,7 +101,7 @@
101101
Html::header($itemtype::getTypeName(), $_SERVER['PHP_SELF'],
102102
"assets", ($menu!==false?$menu:$itemtype), strtolower($itemtype));
103103

104-
$item->display($_GET, array( 'withtemplate' => $_GET["withtemplate"]));
104+
$item->display($_GET, ['withtemplate' => $_GET["withtemplate"]]);
105105

106106
Html::footer();
107107
} else {

front/profile.form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333

3434
/* save profile */
3535
if (isset($_POST['update_all_rights']) && isset($_POST['itemtype'])) {
36-
$profiles = array();
36+
$profiles = [];
3737
foreach ($_POST as $key => $val) {
3838
if (preg_match("/^profile_/", $key)) {
3939
$id = preg_replace("/^profile_/", "", $key);
40-
$profiles[$id] = array(
40+
$profiles[$id] = [
4141
"id" => $id,
4242
"_".PluginGenericobjectProfile::getProfileNameForItemtype($_POST['itemtype']) => $val
43-
);
43+
];
4444
}
4545
}
4646
_log($profiles);

front/type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
$type->getFromDBByType($_GET['itemtype']);
3535
Html::redirect(Toolbox::getItemTypeFormURL('PluginGenericobjectType').'?id='.$type->getID());
3636

37-
} else if (Session::haveRightsOr('plugin_genericobject_types', array(READ, CREATE, UPDATE, PURGE))) {
37+
} else if (Session::haveRightsOr('plugin_genericobject_types', [READ, CREATE, UPDATE, PURGE])) {
3838
Html::header(__("Type of objects", "genericobject"), $_SERVER['PHP_SELF'], "config",
3939
"PluginGenericobjectType");
4040
Search::Show('PluginGenericobjectType');

hook.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function plugin_genericobject_AssignToTicket($types) {
5252
// Define Dropdown tables to be manage in GLPI :
5353
function plugin_genericobject_getDropdown() {
5454

55-
$dropdowns = array('PluginGenericobjectTypeFamily' => PluginGenericobjectTypeFamily::getTypeName(2));
55+
$dropdowns = ['PluginGenericobjectTypeFamily' => PluginGenericobjectTypeFamily::getTypeName(2)];
5656

5757
$plugin = new Plugin();
5858
if ($plugin->isActivated("genericobject")) {
@@ -72,7 +72,7 @@ function plugin_genericobject_getDropdown() {
7272

7373
// Define dropdown relations
7474
function plugin_genericobject_getDatabaseRelations() {
75-
$dropdowns = array();
75+
$dropdowns = [];
7676

7777
//TODO : purt here relations
7878
/*
@@ -81,15 +81,15 @@ function plugin_genericobject_getDatabaseRelations() {
8181
foreach(getAllDatasFromTable(getTableForItemType('PluginGenericobjectType'),
8282
"`is_active`='1'") as $itemtype) {
8383
foreach(PluginGenericobjectType::getDropdownForItemtype($itemtype) as $table) {
84-
$dropdowns[$table][] = array()
84+
$dropdowns[$table][] = []
8585
}
8686
}
8787
}
8888
*/
8989
return $dropdowns;
9090
}
9191

92-
function plugin_uninstall_addUninstallTypes($uninstal_types = array()) {
92+
function plugin_uninstall_addUninstallTypes($uninstal_types = []) {
9393
foreach (PluginGenericobjectType::getTypes() as $tmp => $type) {
9494
if ($type["use_plugin_uninstall"]) {
9595
$uninstal_types[] = $type["itemtype"];
@@ -113,15 +113,14 @@ function plugin_genericobject_install() {
113113

114114
$migration = new Migration(PLUGIN_GENERICOBJECT_VERSION);
115115

116-
foreach (array(
117-
'PluginGenericobjectField',
118-
'PluginGenericobjectCommonDropdown',
119-
'PluginGenericobjectCommonTreeDropdown',
120-
'PluginGenericobjectProfile',
121-
'PluginGenericobjectType',
122-
'PluginGenericobjectTypeFamily'
123-
) as $itemtype
124-
) {
116+
foreach ([
117+
'PluginGenericobjectField',
118+
'PluginGenericobjectCommonDropdown',
119+
'PluginGenericobjectCommonTreeDropdown',
120+
'PluginGenericobjectProfile',
121+
'PluginGenericobjectType',
122+
'PluginGenericobjectTypeFamily'
123+
] as $itemtype) {
125124
if ($plug=isPluginItemType($itemtype)) {
126125
$plugname = strtolower($plug['plugin']);
127126
$dir = GLPI_ROOT . "/plugins/$plugname/inc/";
@@ -167,13 +166,12 @@ function plugin_genericobject_uninstall() {
167166
}
168167
}
169168

170-
foreach (array(
171-
'PluginGenericobjectType',
172-
'PluginGenericobjectProfile',
173-
'PluginGenericobjectField',
174-
'PluginGenericobjectTypeFamily'
175-
) as $itemtype
176-
) {
169+
foreach ([
170+
'PluginGenericobjectType',
171+
'PluginGenericobjectProfile',
172+
'PluginGenericobjectField',
173+
'PluginGenericobjectTypeFamily'
174+
] as $itemtype) {
177175
if ($plug=isPluginItemType($itemtype)) {
178176
$plugname = strtolower($plug['plugin']);
179177
$dir = GLPI_ROOT . "/plugins/$plugname/inc/";
@@ -212,12 +210,12 @@ function plugin_genericobject_MassiveActions($type) {
212210
if (isset($types[$type])) {
213211
$objecttype = PluginGenericobjectType::getInstance($type);
214212
if ($objecttype->isTransferable()) {
215-
return array('PluginGenericobjectObject'.
216-
MassiveAction::CLASS_ACTION_SEPARATOR.'plugin_genericobject_transfer' => __("Transfer"));
213+
return ['PluginGenericobjectObject'.
214+
MassiveAction::CLASS_ACTION_SEPARATOR.'plugin_genericobject_transfer' => __("Transfer")];
217215
} else {
218-
return array();
216+
return [];
219217
}
220218
} else {
221-
return array();
219+
return [];
222220
}
223221
}

inc/autoload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class PluginGenericobjectAutoloader implements SplAutoloader
66
{
7-
protected $paths = array();
7+
protected $paths = [];
88

99
public function __construct($options = null) {
1010
if (null !== $options) {
@@ -47,11 +47,11 @@ public function autoload($classname) {
4747
return false;
4848
}
4949

50-
$filename = implode(".", array(
50+
$filename = implode(".", [
5151
$class_name,
5252
"class",
5353
"php"
54-
));
54+
]);
5555

5656
foreach ($this->paths as $path) {
5757
$test = $path . DIRECTORY_SEPARATOR . $filename;
@@ -64,6 +64,6 @@ public function autoload($classname) {
6464
}
6565

6666
public function register() {
67-
spl_autoload_register(array($this, 'autoload'));
67+
spl_autoload_register([$this, 'autoload']);
6868
}
6969
}

inc/field.class.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public static function showObjectFieldsForm($id) {
4040
$object_type->getFromDB($id);
4141
$itemtype = $object_type->fields['itemtype'];
4242
$fields_in_db = PluginGenericobjectSingletonObjectField::getInstance($itemtype);
43-
$used_fields = array();
43+
$used_fields = [];
4444

4545
//Reset fields definition only to keep the itemtype ones
46-
$GO_FIELDS = array();
46+
$GO_FIELDS = [];
4747
plugin_genericobject_includeCommonFields(true);
4848

4949
PluginGenericobjectType::includeConstants($object_type->fields['name'], true);
@@ -218,13 +218,13 @@ static function getFieldName($field, $itemtype, $options, $remove_prefix = false
218218
*
219219
* @return the dropdown random ID
220220
*/
221-
static function dropdownFields($name,$itemtype, $used = array()) {
221+
static function dropdownFields($name,$itemtype, $used = []) {
222222
global $GO_FIELDS;
223223

224-
$dropdown_types = array();
224+
$dropdown_types = [];
225225
foreach ($GO_FIELDS as $field => $values) {
226226
$message = "";
227-
$field_options = array();
227+
$field_options = [];
228228
$field = self::getFieldName($field, $itemtype, $values, false);
229229
if (!in_array($field, $used)) {
230230
if (!isset($dropdown_types[$field])) {
@@ -266,7 +266,7 @@ static function dropdownFields($name,$itemtype, $used = array()) {
266266
}
267267

268268
ksort($dropdown_types);
269-
return Dropdown::showFromArray($name, $dropdown_types, array('display' => false));
269+
return Dropdown::showFromArray($name, $dropdown_types, ['display' => false]);
270270
}
271271

272272
/**
@@ -287,10 +287,10 @@ static function getFieldOptions($field, $itemtype="") {
287287
// This field has been dynamically defined because it's an isolated dropdown
288288
$tmpfield = self::getFieldName(
289289
$field, $itemtype,
290-
array(
290+
[
291291
'dropdown_type' => 'isolated',
292-
'input_type' => 'dropdown'
293-
),
292+
'input_type' => 'dropdown'
293+
],
294294
true
295295
);
296296
$options = $GO_FIELDS[$tmpfield];
@@ -325,16 +325,16 @@ public static function displayFieldDefinition($target, $itemtype, $field, $index
325325
echo "<td width='10'>";
326326
if ((!$blacklist || $readonly) && $index > 1) {
327327
Html::showSimpleForm($target, $CFG_GLPI["root_doc"] . "/pics/deplier_up.png", 'up',
328-
array('field' => $field, 'action' => 'up', 'itemtype' => $itemtype),
329-
$CFG_GLPI["root_doc"] . "/pics/deplier_up.png");
328+
['field' => $field, 'action' => 'up', 'itemtype' => $itemtype],
329+
$CFG_GLPI["root_doc"] . "/pics/deplier_up.png");
330330
}
331331
echo "</td>";
332332

333333
echo "<td width='10'>";
334334
if ((!$blacklist || $readonly) && !$last) {
335335
Html::showSimpleForm($target, $CFG_GLPI["root_doc"] . "/pics/deplier_down.png", 'down',
336-
array('field' => $field, 'action' => 'down', 'itemtype' => $itemtype),
337-
$CFG_GLPI["root_doc"] . "/pics/deplier_down.png");
336+
['field' => $field, 'action' => 'down', 'itemtype' => $itemtype],
337+
$CFG_GLPI["root_doc"] . "/pics/deplier_down.png");
338338
}
339339
echo "</td>";
340340

@@ -453,8 +453,10 @@ static function deleteDisplayPreferences($table, $field) {
453453
foreach ($searchopt as $num => $option) {
454454
if ((isset($option['field']) && ($option['field'] == $field))
455455
|| (isset($option['field']) && $option['linkfield'] == $field)) {
456-
$criteria = array('itemtype' => $itemtype, 'num' => $num);
457-
$pref->deleteByCriteria($criteria);
456+
$pref->deleteByCriteria([
457+
'itemtype' => $itemtype,
458+
'num' => $num
459+
]);
458460
break;
459461
}
460462
}
@@ -465,7 +467,7 @@ static function deleteDisplayPreferences($table, $field) {
465467
* @params an array which contains the itemtype, the field to move and the action (up/down)
466468
* @return nothing
467469
*/
468-
static function changeFieldOrder($params = array()) {
470+
static function changeFieldOrder($params = []) {
469471
global $DB;
470472
$itemtype = $params['itemtype'];
471473
$field = $params['field'];
@@ -510,7 +512,7 @@ public static function checkNecessaryFieldsDelete($itemtype,$field) {
510512
}
511513
/*
512514
if ($type->fields['use_direct_connections']) {
513-
foreach(array('users_id','groups_id',' states_id','locations_id') as $tmp_field) {
515+
foreach(['users_id','groups_id',' states_id','locations_id'] as $tmp_field) {
514516
if ($tmp_field == $field) {
515517
return false;
516518
}

inc/functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function dropdown_getTypeName($class,$nb=0) {
2626
}
2727
}
2828
global $LOG_FILTER;
29-
$LOG_FILTER = array();
29+
$LOG_FILTER = [];
3030
/*
3131
* a simple logger function
3232
* You can disable logging by using the global $LOG_FILTER
@@ -35,12 +35,12 @@ function dropdown_getTypeName($class,$nb=0) {
3535
function _log() {
3636
global $LOG_FILTER;
3737
$trace = debug_backtrace();
38-
//call_user_func_array("Toolbox::logInFile", array('generic-object', print_r($trace,true) . "\n", true));
38+
//call_user_func_array("Toolbox::logInFile", ['generic-object', print_r($trace,true) . "\n", true]);
3939
if (count($trace)>0) {
4040
$glpi_root = str_replace( "\\", "/", GLPI_ROOT );
4141
$trace_file = str_replace( "\\", "/", $trace[0]['file'] );
4242
$filename = preg_replace("|^".$glpi_root."/plugins/genericobject/|", "", $trace_file);
43-
//call_user_func_array("Toolbox::logInFile", array('generic-object', $filename . "\n", true));
43+
//call_user_func_array("Toolbox::logInFile", ['generic-object', $filename . "\n", true]);
4444
}
4545
if (count($trace) > 1) {
4646
$caller = $trace[1];
@@ -61,7 +61,7 @@ function _log() {
6161
$show_log = true;
6262
}
6363
if ($show_log) {
64-
call_user_func_array("Toolbox::logInFile", array('generic-object', $msg, true));
64+
call_user_func_array("Toolbox::logInFile", ['generic-object', $msg, true]);
6565
}
6666
}
6767

0 commit comments

Comments
 (0)