(NFC) Update CRM/Core CRM/Custom CRM/Dedupe to match the new coder style
[civicrm-core.git] / CRM / Custom / Form / ChangeFieldType.php
index 1b05717e2f180a00d42e6603c632773b6ddbad26..7e89f123826ba8a7b825b61174a445b68b1f4f77 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  * $Id$
  *
  */
@@ -47,11 +47,13 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
 
   /**
    * Array of custom field values
+   * @var array
    */
   protected $_values;
 
   /**
    * Mapper array of valid field type
+   * @var array
    */
   protected $_htmlTypeTransitions;
 
@@ -66,8 +68,8 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
       $this, TRUE
     );
 
-    $this->_values = array();
-    $params = array('id' => $this->_id);
+    $this->_values = [];
+    $params = ['id' => $this->_id];
     CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
 
     $this->_htmlTypeTransitions = self::fieldTypeTransitions(CRM_Utils_Array::value('data_type', $this->_values),
@@ -85,7 +87,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $session->pushUserContext($url);
 
     CRM_Utils_System::setTitle(ts('Change Field Type: %1',
-      array(1 => $this->_values['label'])
+      [1 => $this->_values['label']]
     ));
   }
 
@@ -99,7 +101,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $srcHtmlType = $this->add('select',
       'src_html_type',
       ts('Current HTML Type'),
-      array($this->_values['html_type'] => $this->_values['html_type']),
+      [$this->_values['html_type'] => $this->_values['html_type']],
       TRUE
     );
 
@@ -111,25 +113,24 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $dstHtmlType = $this->add('select',
       'dst_html_type',
       ts('New HTML Type'),
-      array(
+      [
         '' => ts('- select -'),
-      ) + $this->_htmlTypeTransitions,
+      ] + $this->_htmlTypeTransitions,
       TRUE
     );
 
-    $this->addButtons(array(
-        array(
-          'type' => 'next',
-          'name' => ts('Change Field Type'),
-          'isDefault' => TRUE,
-          'js' => array('onclick' => 'return checkCustomDataField();'),
-        ),
-        array(
-          'type' => 'cancel',
-          'name' => ts('Cancel'),
-        ),
-      )
-    );
+    $this->addButtons([
+      [
+        'type' => 'next',
+        'name' => ts('Change Field Type'),
+        'isDefault' => TRUE,
+        'js' => ['onclick' => 'return checkCustomDataField();'],
+      ],
+      [
+        'type' => 'cancel',
+        'name' => ts('Cancel'),
+      ],
+    ]);
   }
 
   /**
@@ -145,17 +146,17 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
       'table_name'
     );
 
-    $singleValueOps = array(
+    $singleValueOps = [
       'Text',
       'Select',
       'Radio',
       'Autocomplete-Select',
-    );
+    ];
 
-    $mutliValueOps = array(
+    $mutliValueOps = [
       'CheckBox',
       'Multi-Select',
-    );
+    ];
 
     $srcHtmlType = $this->_values['html_type'];
     $dstHtmlType = $params['dst_html_type'];
@@ -164,24 +165,21 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $customField->id = $this->_id;
     $customField->find(TRUE);
 
-    if ($dstHtmlType == 'Text' && in_array($srcHtmlType, array(
-        'Select',
-        'Radio',
-        'Autocomplete-Select',
-      ))
-    ) {
+    if ($dstHtmlType == 'Text' && in_array($srcHtmlType, [
+      'Select',
+      'Radio',
+      'Autocomplete-Select',
+    ])) {
       $customField->option_group_id = "NULL";
       CRM_Core_BAO_CustomField::checkOptionGroup($this->_values['option_group_id']);
     }
 
     if (in_array($srcHtmlType, $mutliValueOps) &&
-      in_array($dstHtmlType, $singleValueOps)
-    ) {
+      in_array($dstHtmlType, $singleValueOps)) {
       $this->flattenToFirstValue($tableName, $this->_values['column_name']);
     }
     elseif (in_array($srcHtmlType, $singleValueOps) &&
-      in_array($dstHtmlType, $mutliValueOps)
-    ) {
+      in_array($dstHtmlType, $mutliValueOps)) {
       $this->firstValueToFlatten($tableName, $this->_values['column_name']);
     }
 
@@ -192,7 +190,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
 
     CRM_Core_Session::setStatus(ts('Input type of custom field \'%1\' has been successfully changed to \'%2\'.',
-      array(1 => $this->_values['label'], 2 => $dstHtmlType)
+      [1 => $this->_values['label'], 2 => $dstHtmlType]
     ), ts('Field Type Changed'), 'success');
   }
 
@@ -209,17 +207,17 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
       return NULL;
     }
 
-    $singleValueOps = array(
+    $singleValueOps = [
       'Text' => 'Text',
       'Select' => 'Select',
       'Radio' => 'Radio',
       'Autocomplete-Select' => 'Autocomplete-Select',
-    );
+    ];
 
-    $mutliValueOps = array(
+    $mutliValueOps = [
       'CheckBox' => 'CheckBox',
       'Multi-Select' => 'Multi-Select',
-    );
+    ];
 
     switch ($dataType) {
       case 'String':
@@ -248,10 +246,10 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
         break;
 
       case 'Memo':
-        $ops = array(
+        $ops = [
           'TextArea' => 'TextArea',
           'RichTextEditor' => 'RichTextEditor',
-        );
+        ];
         if (in_array($htmlType, array_keys($ops))) {
           unset($ops[$htmlType]);
           return $ops;
@@ -278,10 +276,10 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
         continue;
       }
       $value = CRM_Core_DAO::VALUE_SEPARATOR . $dao->{$column} . CRM_Core_DAO::VALUE_SEPARATOR;
-      $params = array(
-        1 => array((string) $value, 'String'),
-        2 => array($dao->id, 'Integer'),
-      );
+      $params = [
+        1 => [(string) $value, 'String'],
+        2 => [$dao->id, 'Integer'],
+      ];
       CRM_Core_DAO::executeQuery($updateSql, $params);
     }
   }
@@ -299,10 +297,10 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $dao = CRM_Core_DAO::executeQuery($selectSql);
     while ($dao->fetch()) {
       $values = self::explode($dao->{$column});
-      $params = array(
-        1 => array((string) array_shift($values), 'String'),
-        2 => array($dao->id, 'Integer'),
-      );
+      $params = [
+        1 => [(string) array_shift($values), 'String'],
+        2 => [$dao->id, 'Integer'],
+      ];
       CRM_Core_DAO::executeQuery($updateSql, $params);
     }
   }
@@ -314,7 +312,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
    */
   public static function explode($str) {
     if (empty($str) || $str == CRM_Core_DAO::VALUE_SEPARATOR . CRM_Core_DAO::VALUE_SEPARATOR) {
-      return array();
+      return [];
     }
     else {
       return explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($str, CRM_Core_DAO::VALUE_SEPARATOR));