Fix coding standards violations

This commit is contained in:
Cédric Anne 2018-06-22 12:09:53 +02:00
parent 72a8c561ea
commit da86b4e48a
8 changed files with 100 additions and 100 deletions

View File

@ -37,10 +37,10 @@
function plugin_change_profile_example() {
// For example : same right of computer
if (Session::haveRight('computer', UPDATE)) {
$_SESSION["glpi_plugin_example_profile"] = array('example' => 'w');
$_SESSION["glpi_plugin_example_profile"] = ['example' => 'w'];
} else if (Session::haveRight('computer', READ)) {
$_SESSION["glpi_plugin_example_profile"] = array('example' => 'r');
$_SESSION["glpi_plugin_example_profile"] = ['example' => 'r'];
} else {
unset($_SESSION["glpi_plugin_example_profile"]);
@ -50,14 +50,14 @@ function plugin_change_profile_example() {
// Define dropdown relations
function plugin_example_getDatabaseRelations() {
return array("glpi_plugin_example_dropdowns" => array("glpi_plugin_example" => "plugin_example_dropdowns_id"));
return ["glpi_plugin_example_dropdowns" => ["glpi_plugin_example" => "plugin_example_dropdowns_id"]];
}
// Define Dropdown tables to be manage in GLPI :
function plugin_example_getDropdown() {
// Table => Name
return array('PluginExampleDropdown' => __("Plugin Example Dropdown", 'example'));
return ['PluginExampleDropdown' => __("Plugin Example Dropdown", 'example')];
}
@ -66,7 +66,7 @@ function plugin_example_getDropdown() {
// Define Additionnal search options for types (other than the plugin ones)
function plugin_example_getAddSearchOptions($itemtype) {
$sopt = array();
$sopt = [];
if ($itemtype == 'Computer') {
// Just for example, not working...
$sopt[1001]['table'] = 'glpi_plugin_example_dropdowns';
@ -93,7 +93,7 @@ function plugin_example_getAddSearchOptionsNew($itemtype) {
}
// See also PluginExampleExample::getSpecificValueToDisplay()
function plugin_example_giveItem($type,$ID,$data,$num) {
function plugin_example_giveItem($type, $ID, $data, $num) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
@ -231,7 +231,7 @@ function plugin_example_addHaving($link, $nott, $type, $ID, $val, $num) {
}
function plugin_example_addSelect($type,$ID,$num) {
function plugin_example_addSelect($type, $ID, $num) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
@ -246,7 +246,7 @@ function plugin_example_addSelect($type,$ID,$num) {
}
function plugin_example_addOrderBy($type,$ID,$order,$key=0) {
function plugin_example_addOrderBy($type, $ID, $order, $key = 0) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
@ -270,18 +270,18 @@ function plugin_example_MassiveActions($type) {
switch ($type) {
// New action for core and other plugin types : name = plugin_PLUGINNAME_actionname
case 'Computer' :
return array('PluginExampleExample'.MassiveAction::CLASS_ACTION_SEPARATOR.'DoIt' =>
__("plugin_example_DoIt", 'example'));
return ['PluginExampleExample'.MassiveAction::CLASS_ACTION_SEPARATOR.'DoIt' =>
__("plugin_example_DoIt", 'example')];
// Actions for types provided by the plugin are included inside the classes
}
return array();
return [];
}
// How to display specific update fields ?
// options must contain at least itemtype and options array
function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
function plugin_example_MassiveActionsFieldsDisplay($options = []) {
//$type,$table,$field,$linkfield
$table = $options['options']['table'];
@ -316,7 +316,7 @@ function plugin_example_MassiveActionsFieldsDisplay($options=array()) {
// How to display specific search fields or dropdown ?
// options must contain at least itemtype and options array
// MUST Use a specific AddWhere & $tab[X]['searchtype'] = 'equals'; declaration
function plugin_example_searchOptionsValues($options=array()) {
function plugin_example_searchOptionsValues($options = []) {
$table = $options['searchoption']['table'];
$field = $options['searchoption']['field'];
@ -325,9 +325,9 @@ function plugin_example_searchOptionsValues($options=array()) {
case "glpi_plugin_example_examples.serial" :
echo __("Not really specific - Use your own dropdown - Just for example", 'example');
Dropdown::show(getItemTypeForTable($options['searchoption']['table']),
array('value' => $options['value'],
'name' => $options['name'],
'comments' => 0));
['value' => $options['value'],
'name' => $options['name'],
'comments' => 0]);
// Need to return true if specific display
return true;
}
@ -447,9 +447,9 @@ function plugin_example_addParamFordynamicReport($itemtype) {
if ($itemtype == 'PluginExampleExample') {
// Return array data containing all params to add : may be single data or array data
// Search config are available from session variable
return array('add1' => $_SESSION['glpisearch'][$itemtype]['order'],
'add2' => array('tutu' => 'Second Add',
'Other Data'));
return ['add1' => $_SESSION['glpisearch'][$itemtype]['order'],
'add2' => ['tutu' => 'Second Add',
'Other Data']];
}
// Return false or a non array data if not needed
return false;
@ -465,9 +465,9 @@ function plugin_example_install() {
global $DB;
$config = new Config();
$config->setConfigurationValues('plugin:Example', array('configuration' => false));
$config->setConfigurationValues('plugin:Example', ['configuration' => false]);
ProfileRight::addProfileRights(array('example:read'));
ProfileRight::addProfileRights(['example:read']);
if (!$DB->tableExists("glpi_plugin_example_examples")) {
$query = "CREATE TABLE `glpi_plugin_example_examples` (
@ -546,7 +546,7 @@ function plugin_example_install() {
// To be called for each task the plugin manage
// task in class
CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, array('param' => 50));
CronTask::Register('PluginExampleExample', 'Sample', DAY_TIMESTAMP, ['param' => 50]);
return true;
}
@ -560,14 +560,14 @@ function plugin_example_uninstall() {
global $DB;
$config = new Config();
$config->deleteConfigurationValues('plugin:Example', array('configuration' => false));
$config->deleteConfigurationValues('plugin:Example', ['configuration' => false]);
ProfileRight::deleteProfileRights(array('example:read'));
ProfileRight::deleteProfileRights(['example:read']);
$notif = new Notification();
$options = array('itemtype' => 'Ticket',
'event' => 'plugin_example',
'FIELDS' => 'id');
$options = ['itemtype' => 'Ticket',
'event' => 'plugin_example',
'FIELDS' => 'id'];
foreach ($DB->request('glpi_notifications', $options) as $data) {
$notif->delete($data);
}

View File

@ -31,7 +31,7 @@ class PluginExampleConfig extends CommonDBTM {
static protected $notable = true;
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if (!$withtemplate) {
if ($item->getType() == 'Config') {
@ -75,7 +75,7 @@ class PluginExampleConfig extends CommonDBTM {
Html::closeForm();
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Config') {
$config = new self();

View File

@ -41,7 +41,7 @@ if (!defined('GLPI_ROOT')) {
/// Class DeviceCamera
class PluginExampleDeviceCamera extends CommonDevice {
static function getTypeName($nb=0) {
static function getTypeName($nb = 0) {
return _n('Camera', 'Cameras', $nb);
}

View File

@ -36,7 +36,7 @@
class PluginExampleDropdown extends CommonDropdown {
static function getTypeName($nb=0) {
static function getTypeName($nb = 0) {
if ($nb > 0) {
return __('Plugin Example Dropdowns', 'example');

View File

@ -75,7 +75,7 @@ class PluginExampleExample extends CommonDBTM {
**/
static function getAdditionalMenuLinks() {
global $CFG_GLPI;
$links = array();
$links = [];
$links['config'] = '/plugins/example/index.php';
$links["<img src='".$CFG_GLPI["root_doc"]."/pics/menu_showall.png' title='".__s('Show all')."' alt='".__s('Show all')."'>"] = '/plugins/example/index.php';
@ -84,16 +84,16 @@ class PluginExampleExample extends CommonDBTM {
return $links;
}
function defineTabs($options = array()) {
function defineTabs($options = []) {
$ong = array();
$ong = [];
$this->addDefaultFormTab($ong);
$this->addStandardTab('Link', $ong, $options);
return $ong;
}
function showForm($ID, $options = array()) {
function showForm($ID, $options = []) {
global $CFG_GLPI;
$this->initForm($ID, $options);
@ -167,10 +167,10 @@ class PluginExampleExample extends CommonDBTM {
switch ($name) {
case 'Sample' :
return array('description' => __('Cron description for example', 'example'),
'parameter' => __('Cron parameter for example', 'example'));
return ['description' => __('Cron description for example', 'example'),
'parameter' => __('Cron parameter for example', 'example')];
}
return array();
return [];
}
@ -206,20 +206,20 @@ class PluginExampleExample extends CommonDBTM {
}
// Hook done on before add item case (data altered by object prepareInputForAdd)
static function post_prepareadd_computer(Computer$item) {
static function post_prepareadd_computer(Computer $item) {
Session::addMessageAfterRedirect("Post prepareAdd Computer Hook", true);
}
// Hook done on add item case
static function item_add_computer(Computer$item) {
static function item_add_computer(Computer $item) {
Session::addMessageAfterRedirect("Add Computer Hook, ID=".$item->getID(), true);
return true;
}
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if (!$withtemplate) {
switch ($item->getType()) {
@ -238,14 +238,14 @@ class PluginExampleExample extends CommonDBTM {
case 'ComputerDisk' :
case 'Supplier' :
return array(1 => __("Test Plugin", 'example'),
2 => __("Test Plugin 2", 'example'));
return [1 => __("Test Plugin", 'example'),
2 => __("Test Plugin 2", 'example')];
case 'Computer' :
case 'Central' :
case 'Preference':
case 'Notification':
return array(1 => __("Test Plugin", 'example'));
return [1 => __("Test Plugin", 'example')];
}
}
@ -253,7 +253,7 @@ class PluginExampleExample extends CommonDBTM {
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
switch ($item->getType()) {
case 'Phone' :
@ -304,10 +304,10 @@ class PluginExampleExample extends CommonDBTM {
return true;
}
static function getSpecificValueToDisplay($field, $values, array $options=array()) {
static function getSpecificValueToDisplay($field, $values, array $options = []) {
if (!is_array($values)) {
$values = array($field => $values);
$values = [$field => $values];
}
switch ($field) {
case 'serial' :
@ -323,7 +323,7 @@ class PluginExampleExample extends CommonDBTM {
// Add items in the output array
// Items need to have an unique index beginning by the begin date of the item to display
// needed to be correcly displayed
$output = array();
$output = [];
$key = $parm["begin"]."$$$"."plugin_example1";
$output[$key]["begin"] = date("Y-m-d 17:00:00");
$output[$key]["end"] = date("Y-m-d 18:00:00");
@ -345,7 +345,7 @@ class PluginExampleExample extends CommonDBTM {
*
* @return Nothing (display function)
**/
static function displayPlanningItem(array $val, $who, $type="", $complete=0) {
static function displayPlanningItem(array $val, $who, $type = "", $complete = 0) {
// $parm["type"] say begin end in or from type
// Add items in the items fields of the parm array
@ -401,7 +401,7 @@ class PluginExampleExample extends CommonDBTM {
*
* @see CommonDBTM::getSpecificMassiveActions()
**/
function getSpecificMassiveActions($checkitem=NULL) {
function getSpecificMassiveActions($checkitem = null) {
$actions = parent::getSpecificMassiveActions($checkitem);
@ -424,11 +424,11 @@ class PluginExampleExample extends CommonDBTM {
switch ($ma->getAction()) {
case 'DoIt':
echo "&nbsp;<input type='hidden' name='toto' value='1'>".
Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')).
Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']).
" ".__('Write in item history', 'example');
return true;
case 'do_nothing' :
echo "&nbsp;".Html::submit(_x('button', 'Post'), array('name' => 'massiveaction')).
echo "&nbsp;".Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']).
" ".__('but do nothing :)', 'example');
return true;
}
@ -450,7 +450,7 @@ class PluginExampleExample extends CommonDBTM {
if ($item->getType() == 'Computer') {
Session::addMessageAfterRedirect(__("Right it is the type I want...", 'example'));
Session::addMessageAfterRedirect(__('Write in item history', 'example'));
$changes = array(0, 'old value', 'new value');
$changes = [0, 'old value', 'new value'];
foreach ($ids as $id) {
if ($item->getFromDB($id)) {
Session::addMessageAfterRedirect("- ".$item->getField("name"));
@ -494,7 +494,7 @@ class PluginExampleExample extends CommonDBTM {
if (strstr($link, "[EXAMPLE_ID]")) {
$link = str_replace("[EXAMPLE_ID]", $item->getID(), $link);
return array($link);
return [$link];
}
return parent::generateLinkContents($link, $item);

View File

@ -35,10 +35,10 @@ if (!defined('GLPI_ROOT')) {
class PluginExampleNotificationTargetExample extends NotificationTarget {
function getEvents() {
return array ('alert' => 'alert example');
return ['alert' => 'alert example'];
}
function addDataForTemplate($event, $options=array()) {
function addDataForTemplate($event, $options = []) {
global $DB, $CFG_GLPI;
$this->data['##example.name##'] = __('Example', 'example');

View File

@ -62,7 +62,7 @@ class PluginExampleRuleTest extends Rule {
function getCriterias() {
$criterias = array();
$criterias = [];
$criterias['name']['field'] = 'name';
$criterias['name']['name'] = __('Software');
$criterias['name']['table'] = 'glpi_softwares';
@ -73,7 +73,7 @@ class PluginExampleRuleTest extends Rule {
function getActions() {
$actions = array();
$actions = [];
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
$actions['softwarecategories_id']['type'] = 'dropdown';
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';

View File

@ -48,23 +48,23 @@ function plugin_init_example() {
// array('classname' => 'PluginExampleExample',
// ));
Plugin::registerClass('PluginExampleConfig', array('addtabon' => 'Config'));
Plugin::registerClass('PluginExampleConfig', ['addtabon' => 'Config']);
// Params : plugin name - string type - ID - Array of attributes
Plugin::registerClass('PluginExampleDropdown');
$types = array('Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
'Preference', 'Profile', 'Supplier');
$types = ['Central', 'Computer', 'ComputerDisk', 'Notification', 'Phone',
'Preference', 'Profile', 'Supplier'];
Plugin::registerClass('PluginExampleExample',
array('notificationtemplates_types' => true,
'addtabon' => $types,
'link_types' => true));
['notificationtemplates_types' => true,
'addtabon' => $types,
'link_types' => true]);
Plugin::registerClass('PluginExampleRuleTestCollection',
array('rulecollections_types' => true));
['rulecollections_types' => true]);
Plugin::registerClass('PluginExampleDeviceCamera',
array('device_types' => true));
['device_types' => true]);
if (version_compare(GLPI_VERSION, '9.1', 'ge')) {
if (class_exists('PluginExampleExample')) {
@ -74,8 +74,8 @@ function plugin_init_example() {
// Display a menu entry ?
$_SESSION["glpi_plugin_example_profile"]['example'] = 'w';
if (isset($_SESSION["glpi_plugin_example_profile"])) { // Right set in change_profile hook
$PLUGIN_HOOKS['menu_toadd']['example'] = array('plugins' => 'PluginExampleExample',
'tools' => 'PluginExampleExample');
$PLUGIN_HOOKS['menu_toadd']['example'] = ['plugins' => 'PluginExampleExample',
'tools' => 'PluginExampleExample'];
// Old menu style
// $PLUGIN_HOOKS['menu_entry']['example'] = 'front/example.php';
@ -104,45 +104,45 @@ function plugin_init_example() {
//$PLUGIN_HOOKS['change_entity']['example'] = 'plugin_change_entity_example';
// Item action event // See define.php for defined ITEM_TYPE
$PLUGIN_HOOKS['pre_item_update']['example'] = array('Computer' => 'plugin_pre_item_update_example');
$PLUGIN_HOOKS['item_update']['example'] = array('Computer' => 'plugin_item_update_example');
$PLUGIN_HOOKS['pre_item_update']['example'] = ['Computer' => 'plugin_pre_item_update_example'];
$PLUGIN_HOOKS['item_update']['example'] = ['Computer' => 'plugin_item_update_example'];
$PLUGIN_HOOKS['item_empty']['example'] = array('Computer' => 'plugin_item_empty_example');
$PLUGIN_HOOKS['item_empty']['example'] = ['Computer' => 'plugin_item_empty_example'];
// Restrict right
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'item_can']];
$PLUGIN_HOOKS['add_default_where']['example'] = ['Computer' => ['PluginExampleComputer', 'add_default_where']];
// Example using a method in class
$PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample',
'pre_item_add_computer'));
$PLUGIN_HOOKS['post_prepareadd']['example'] = array('Computer' => array('PluginExampleExample',
'post_prepareadd_computer'));
$PLUGIN_HOOKS['item_add']['example'] = array('Computer' => array('PluginExampleExample',
'item_add_computer'));
$PLUGIN_HOOKS['pre_item_add']['example'] = ['Computer' => ['PluginExampleExample',
'pre_item_add_computer']];
$PLUGIN_HOOKS['post_prepareadd']['example'] = ['Computer' => ['PluginExampleExample',
'post_prepareadd_computer']];
$PLUGIN_HOOKS['item_add']['example'] = ['Computer' => ['PluginExampleExample',
'item_add_computer']];
$PLUGIN_HOOKS['pre_item_delete']['example'] = array('Computer' => 'plugin_pre_item_delete_example');
$PLUGIN_HOOKS['item_delete']['example'] = array('Computer' => 'plugin_item_delete_example');
$PLUGIN_HOOKS['pre_item_delete']['example'] = ['Computer' => 'plugin_pre_item_delete_example'];
$PLUGIN_HOOKS['item_delete']['example'] = ['Computer' => 'plugin_item_delete_example'];
// Example using the same function
$PLUGIN_HOOKS['pre_item_purge']['example'] = array('Computer' => 'plugin_pre_item_purge_example',
'Phone' => 'plugin_pre_item_purge_example');
$PLUGIN_HOOKS['item_purge']['example'] = array('Computer' => 'plugin_item_purge_example',
'Phone' => 'plugin_item_purge_example');
$PLUGIN_HOOKS['pre_item_purge']['example'] = ['Computer' => 'plugin_pre_item_purge_example',
'Phone' => 'plugin_pre_item_purge_example'];
$PLUGIN_HOOKS['item_purge']['example'] = ['Computer' => 'plugin_item_purge_example',
'Phone' => 'plugin_item_purge_example'];
// Example with 2 different functions
$PLUGIN_HOOKS['pre_item_restore']['example'] = array('Computer' => 'plugin_pre_item_restore_example',
'Phone' => 'plugin_pre_item_restore_example2');
$PLUGIN_HOOKS['item_restore']['example'] = array('Computer' => 'plugin_item_restore_example');
$PLUGIN_HOOKS['pre_item_restore']['example'] = ['Computer' => 'plugin_pre_item_restore_example',
'Phone' => 'plugin_pre_item_restore_example2'];
$PLUGIN_HOOKS['item_restore']['example'] = ['Computer' => 'plugin_item_restore_example'];
// Add event to GLPI core itemtype, event will be raised by the plugin.
// See plugin_example_uninstall for cleanup of notification
$PLUGIN_HOOKS['item_get_events']['example']
= array('NotificationTargetTicket' => 'plugin_example_get_events');
= ['NotificationTargetTicket' => 'plugin_example_get_events'];
// Add datas to GLPI core itemtype for notifications template.
$PLUGIN_HOOKS['item_get_datas']['example']
= array('NotificationTargetTicket' => 'plugin_example_get_datas');
= ['NotificationTargetTicket' => 'plugin_example_get_datas'];
$PLUGIN_HOOKS['item_transfer']['example'] = 'plugin_item_transfer_example';
@ -173,12 +173,12 @@ function plugin_init_example() {
//$PLUGIN_HOOKS['retrieve_more_data_from_ldap']['example']="plugin_retrieve_more_data_from_ldap_example";
// Reports
$PLUGIN_HOOKS['reports']['example'] = array('report.php' => 'New Report',
'report.php?other' => 'New Report 2');
$PLUGIN_HOOKS['reports']['example'] = ['report.php' => 'New Report',
'report.php?other' => 'New Report 2'];
// Stats
$PLUGIN_HOOKS['stats']['example'] = array('stat.php' => 'New stat',
'stat.php?other' => 'New stats 2',);
$PLUGIN_HOOKS['stats']['example'] = ['stat.php' => 'New stat',
'stat.php?other' => 'New stats 2',];
$PLUGIN_HOOKS['post_init']['example'] = 'plugin_example_postinit';
@ -193,21 +193,21 @@ function plugin_init_example() {
// pre_show and post_show for tabs and items,
// see PluginExampleShowtabitem class for implementation explanations
$PLUGIN_HOOKS['pre_show_tab']['example'] = array('PluginExampleShowtabitem', 'pre_show_tab');
$PLUGIN_HOOKS['post_show_tab']['example'] = array('PluginExampleShowtabitem', 'post_show_tab');
$PLUGIN_HOOKS['pre_show_item']['example'] = array('PluginExampleShowtabitem', 'pre_show_item');
$PLUGIN_HOOKS['post_show_item']['example'] = array('PluginExampleShowtabitem', 'post_show_item');
$PLUGIN_HOOKS['pre_show_tab']['example'] = ['PluginExampleShowtabitem', 'pre_show_tab'];
$PLUGIN_HOOKS['post_show_tab']['example'] = ['PluginExampleShowtabitem', 'post_show_tab'];
$PLUGIN_HOOKS['pre_show_item']['example'] = ['PluginExampleShowtabitem', 'pre_show_item'];
$PLUGIN_HOOKS['post_show_item']['example'] = ['PluginExampleShowtabitem', 'post_show_item'];
$PLUGIN_HOOKS['pre_item_form']['example'] = ['PluginExampleItemForm', 'preItemForm'];
$PLUGIN_HOOKS['post_item_form']['example'] = ['PluginExampleItemForm', 'postItemForm'];
// declare this plugin as an import plugin for Computer itemtype
$PLUGIN_HOOKS['import_item']['exemple'] = array('Computer' => array('Plugin'));
$PLUGIN_HOOKS['import_item']['exemple'] = ['Computer' => ['Plugin']];
// add additional informations on Computer::showForm
$PLUGIN_HOOKS['autoinventory_information']['exemple'] = array(
'Computer' => array('PluginExampleComputer', 'showInfo')
);
$PLUGIN_HOOKS['autoinventory_information']['exemple'] = [
'Computer' => ['PluginExampleComputer', 'showInfo']
];
}