From 1643873b30b181f86430476ace48dc4a6a282c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Fri, 22 Jun 2018 15:05:18 +0200 Subject: [PATCH] Fix coding standards violations --- hook.php | 8 ++++---- inc/container.class.php | 30 +++++++++++++++--------------- inc/field.class.php | 8 ++++---- inc/labeltranslation.class.php | 6 +++--- setup.php | 4 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/hook.php b/hook.php index 80849f9e..33e46122 100644 --- a/hook.php +++ b/hook.php @@ -77,7 +77,7 @@ function plugin_fields_install() { $dir = GLPI_ROOT . "/plugins/fields/inc/"; $item =strtolower($plug['class']); if (file_exists("$dir$item.class.php")) { - if (!call_user_func(array($class,'install'), $migration, $version)) { + if (!call_user_func([$class,'install'], $migration, $version)) { return false; } } @@ -136,7 +136,7 @@ function plugin_fields_uninstall() { if (file_exists("$dir$item.class.php")) { include_once ("$dir$item.class.php"); - if (!call_user_func(array($class,'uninstall'))) { + if (!call_user_func([$class,'uninstall'])) { return false; } } @@ -263,11 +263,11 @@ function plugin_fields_rule_matched($params = []) { // update current field $container->updateFieldsValues( - array( + [ 'plugin_fields_containers_id' => $data['id'], $field => $value, 'items_id' => $agent->fields['computers_id'] - ), + ], Computer::getType() ); } diff --git a/inc/container.class.php b/inc/container.class.php index 07335b42..770daea7 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -287,7 +287,7 @@ static function getSpecificValueToDisplay($field, $values, array $options = []) } - function getValueToSelect($field_id_or_search_options, $name = '', $values = '', $options = array()) { + function getValueToSelect($field_id_or_search_options, $name = '', $values = '', $options = []) { switch ($field_id_or_search_options['table'].'.'.$field_id_or_search_options['field']) { // For searchoption "Type" @@ -302,7 +302,7 @@ function getValueToSelect($field_id_or_search_options, $name = '', $values = '', return parent::getValueToSelect($field_id_or_search_options, $name, $values, $options); } - function defineTabs($options = array()) { + function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong); $this->addStandardTab('PluginFieldsField', $ong, $options); @@ -376,8 +376,8 @@ function prepareInputForAdd($input) { } $input['itemtypes'] = isset($input['itemtypes']) - ? json_encode($input['itemtypes'], TRUE) - : NULL; + ? json_encode($input['itemtypes'], true) + : null; return $input; } @@ -401,7 +401,7 @@ function post_addItem() { public static function generateTemplate($fields) { $itemtypes = strlen($fields['itemtypes']) > 0 - ? json_decode($fields['itemtypes'], TRUE) + ? json_decode($fields['itemtypes'], true) : []; foreach ($itemtypes as $itemtype) { $sysname = self::getSystemName($itemtype, $fields['name']); @@ -511,7 +511,7 @@ static function getTypeName($nb = 0) { return __("Block", "fields"); } - public function showForm($ID, $options = array()) { + public function showForm($ID, $options = []) { global $CFG_GLPI; $this->initForm($ID, $options); @@ -605,7 +605,7 @@ public function showForm($ID, $options = array()) { return true; } - static function showFormItemtype($params = array()) { + static function showFormItemtype($params = []) { global $CFG_GLPI; $is_domtab = isset($params['type']) && $params['type'] == 'domtab'; @@ -618,7 +618,7 @@ static function showFormItemtype($params = array()) { 'display_emptychoice' => $is_domtab]); if ($is_domtab) { - Ajax::updateItemOnSelectEvent(array("dropdown_type$rand", "dropdown_itemtypes$rand"), + Ajax::updateItemOnSelectEvent(["dropdown_type$rand", "dropdown_itemtypes$rand"], "subtype_$rand", "../ajax/container_subtype_dropdown.php", ['type' => '__VALUE0__', @@ -827,7 +827,7 @@ static function getEntries($type = 'tab', $full = false) { AND `plugin_fields_containers_id` = '".$item['id']."' AND `right` >= ".READ); $first_found = array_shift($found); - if ($first_found['right'] == NULL || $first_found['right'] == 0) { + if ($first_found['right'] == null || $first_found['right'] == 0) { continue; } @@ -878,7 +878,7 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { // needs to check if entity of item is in hierachy of $tab_name foreach ($container->find("`is_active` = 1 AND `name` = '$tab_name'") as $data) { $dataitemtypes = json_decode($data['itemtypes']); - if (in_array(get_class($item), $dataitemtypes) != FALSE) { + if (in_array(get_class($item), $dataitemtypes) != false) { $entities = [$data['entities_id']]; if ($data['is_recursive']) { $entities = getSonsOf(getTableForItemType('Entity'), $data['entities_id']); @@ -901,7 +901,7 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem $found_c = $container->find("`type` = 'tab' AND `name` = '$tabnum' AND is_active = 1"); foreach ($found_c as $data) { $dataitemtypes = json_decode($data['itemtypes']); - if (in_array(get_class($item), $dataitemtypes) != FALSE) { + if (in_array(get_class($item), $dataitemtypes) != false) { return PluginFieldsField::showForTabContainer($data['id'], $item->fields['id'], get_class($item)); } } @@ -963,7 +963,7 @@ function updateFieldsValues($data, $itemtype, $massiveaction = false) { * @return nothing */ static function constructHistory($containers_id, $items_id, $itemtype, $data, - $old_values = array()) { + $old_values = []) { // Don't log few itemtypes $obj = new $itemtype(); if ($obj->dohistory == false) { @@ -1189,7 +1189,7 @@ static function findContainer($itemtype, $type = 'tab', $subtype = '') { foreach ($itemtypes as $data) { $dataitemtypes = json_decode($data['itemtypes']); $item = new $itemtype(); - if (in_array($item->getType(), $dataitemtypes) != FALSE) { + if (in_array($item->getType(), $dataitemtypes) != false) { $id = $data['id']; } } @@ -1206,7 +1206,7 @@ static function findContainer($itemtype, $type = 'tab', $subtype = '') { $found = $profile->find("`profiles_id` = '".$_SESSION['glpiactiveprofile']['id']."' AND $condition"); $first_found = array_shift($found); - if ($first_found['right'] == NULL || $first_found['right'] == 0) { + if ($first_found['right'] == null || $first_found['right'] == 0) { return false; } } @@ -1291,7 +1291,7 @@ static function preItem(CommonDBTM $item) { //need to check if container is usable on this object entity $loc_c = new PluginFieldsContainer; $loc_c->getFromDB($c_id); - $entities = array($loc_c->fields['entities_id']); + $entities = [$loc_c->fields['entities_id']]; if ($loc_c->fields['is_recursive']) { $entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']); } diff --git a/inc/field.class.php b/inc/field.class.php index b7c86f1f..a700fa30 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -228,7 +228,7 @@ function getNextRanking() { return 0; } - function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { $nb = 0; switch ($item->getType()) { @@ -243,13 +243,13 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { "`plugin_fields_containers_id` = '".$item->getID()."'")); } - static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $fup = new self(); $fup->showSummary($item); return true; } - function defineTabs($options = array()) { + function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong); $this->addStandardTab('PluginFieldsLabelTranslation', $ong, $options); @@ -348,7 +348,7 @@ function showSummary($container) { } - function showForm($ID, $options = array()) { + function showForm($ID, $options = []) { global $CFG_GLPI; if (isset($options['parent_id']) && !empty($options['parent_id'])) { diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index cec1466b..9469a88c 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -63,7 +63,7 @@ static function createForItem(CommonDBTM $item) { return true; } - function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { + function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { $nb = countElementsInTable(self::getTable(), "`plugin_fields_itemtype` = '{$item::getType()}' AND `plugin_fields_items_id` = '{$item->getID()}'"); @@ -71,7 +71,7 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { } - static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { + static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showTranslations($item); } @@ -177,7 +177,7 @@ static function showTranslations(CommonDBTM $item) { * * @return void */ - function showForm($itemtype, $items_id, $id=-1) { + function showForm($itemtype, $items_id, $id = -1) { global $CFG_GLPI; if ($id > 0) { diff --git a/setup.php b/setup.php index 2dfc6f1d..12caa567 100644 --- a/setup.php +++ b/setup.php @@ -81,7 +81,7 @@ function plugin_init_fields() { // Init hook about itemtype(s) for plugin fields if (!isset($PLUGIN_HOOKS['plugin_fields'])) { - $PLUGIN_HOOKS['plugin_fields'] = array(); + $PLUGIN_HOOKS['plugin_fields'] = []; } // When a Category is changed during ticket creation @@ -241,7 +241,7 @@ function plugin_fields_checkFiles($force = false) { foreach ($containers as $container) { $itemtypes = (strlen($container['itemtypes']) > 0) - ? json_decode($container['itemtypes'], TRUE) + ? json_decode($container['itemtypes'], true) : []; foreach ($itemtypes as $itemtype) { $classname = PluginFieldsContainer::getClassname($itemtype, $container['name']);