Merge pull request #15102 from mlutfy/fixPriceSetLabelHtml
[civicrm-core.git] / CRM / Core / ManagedEntities.php
index fe9631d0dbd0a0ef1d5b3bd9413bec6c0e42013b..a3883286963a35fd7e1eef88b2c2655905ab25e3 100644 (file)
@@ -13,11 +13,11 @@ class CRM_Core_ManagedEntities {
    * @return array
    */
   public static function getCleanupOptions() {
-    return array(
+    return [
       'always' => ts('Always'),
       'never' => ts('Never'),
       'unused' => ts('If Unused'),
-    );
+    ];
   }
 
   /**
@@ -55,7 +55,7 @@ class CRM_Core_ManagedEntities {
       function () {
         CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
       },
-      array(),
+      [],
       'ManagedEntities::reconcile'
     );
   }
@@ -92,9 +92,9 @@ class CRM_Core_ManagedEntities {
     $dao->module = $moduleName;
     $dao->name = $name;
     if ($dao->find(TRUE)) {
-      $params = array(
+      $params = [
         'id' => $dao->entity_id,
-      );
+      ];
       $result = NULL;
       try {
         $result = civicrm_api3($dao->entity_type, 'getsingle', $params);
@@ -204,7 +204,7 @@ class CRM_Core_ManagedEntities {
    * unknown modules.
    */
   public function reconcileUnknownModules() {
-    $knownModules = array();
+    $knownModules = [];
     if (array_key_exists(0, $this->moduleIndex) && is_array($this->moduleIndex[0])) {
       $knownModules = array_merge($knownModules, array_keys($this->moduleIndex[0]));
     }
@@ -257,10 +257,11 @@ class CRM_Core_ManagedEntities {
     $doUpdate = ($policy == 'always');
 
     if ($doUpdate) {
-      $defaults = array(
+      $defaults = [
         'id' => $dao->entity_id,
-        'is_active' => 1, // FIXME: test whether is_active is valid
-      );
+      // FIXME: test whether is_active is valid
+        'is_active' => 1,
+      ];
       $params = array_merge($defaults, $todo['params']);
       $result = civicrm_api($dao->entity_type, 'create', $params);
       if ($result['is_error']) {
@@ -284,11 +285,11 @@ class CRM_Core_ManagedEntities {
     // FIXME: if ($dao->entity_type supports is_active) {
     if (TRUE) {
       // FIXME cascading for payproc types?
-      $params = array(
+      $params = [
         'version' => 3,
         'id' => $dao->entity_id,
         'is_active' => 0,
-      );
+      ];
       $result = civicrm_api($dao->entity_type, 'create', $params);
       if ($result['is_error']) {
         $this->onApiError($dao->entity_type, 'create', $params, $result);
@@ -314,10 +315,10 @@ class CRM_Core_ManagedEntities {
         break;
 
       case 'unused':
-        $getRefCount = civicrm_api3($dao->entity_type, 'getrefcount', array(
+        $getRefCount = civicrm_api3($dao->entity_type, 'getrefcount', [
           'debug' => 1,
           'id' => $dao->entity_id,
-        ));
+        ]);
 
         $total = 0;
         foreach ($getRefCount['values'] as $refCount) {
@@ -332,10 +333,10 @@ class CRM_Core_ManagedEntities {
     }
 
     if ($doDelete) {
-      $params = array(
+      $params = [
         'version' => 3,
         'id' => $dao->entity_id,
-      );
+      ];
       $check = civicrm_api3($dao->entity_type, 'get', $params);
       if ((bool) $check['count']) {
         $result = civicrm_api($dao->entity_type, 'delete', $params);
@@ -343,9 +344,9 @@ class CRM_Core_ManagedEntities {
           $this->onApiError($dao->entity_type, 'delete', $params, $result);
         }
       }
-      CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', array(
-        1 => array($dao->id, 'Integer'),
-      ));
+      CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', [
+        1 => [$dao->id, 'Integer'],
+      ]);
     }
   }
 
@@ -356,7 +357,7 @@ class CRM_Core_ManagedEntities {
    */
   public function getDeclarations() {
     if ($this->declarations === NULL) {
-      $this->declarations = array();
+      $this->declarations = [];
       foreach (CRM_Core_Component::getEnabledComponents() as $component) {
         /** @var CRM_Core_Component_Info $component */
         $this->declarations = array_merge($this->declarations, $component->getManagedEntities());
@@ -375,7 +376,7 @@ class CRM_Core_ManagedEntities {
    *   indexed by is_active,name
    */
   protected static function createModuleIndex($modules) {
-    $result = array();
+    $result = [];
     foreach ($modules as $module) {
       $result[$module->is_active][$module->name] = $module;
     }
@@ -390,14 +391,14 @@ class CRM_Core_ManagedEntities {
    *   indexed by module,name
    */
   protected static function createDeclarationIndex($moduleIndex, $declarations) {
-    $result = array();
+    $result = [];
     if (!isset($moduleIndex[TRUE])) {
       return $result;
     }
     foreach ($moduleIndex[TRUE] as $moduleName => $module) {
       if ($module->is_active) {
         // need an empty array() for all active modules, even if there are no current $declarations
-        $result[$moduleName] = array();
+        $result[$moduleName] = [];
       }
     }
     foreach ($declarations as $declaration) {
@@ -414,7 +415,7 @@ class CRM_Core_ManagedEntities {
    */
   protected static function validate($declarations) {
     foreach ($declarations as $declare) {
-      foreach (array('name', 'module', 'entity', 'params') as $key) {
+      foreach (['name', 'module', 'entity', 'params'] as $key) {
         if (empty($declare[$key])) {
           $str = print_r($declare, TRUE);
           return ("Managed Entity is missing field \"$key\": $str");
@@ -448,12 +449,12 @@ class CRM_Core_ManagedEntities {
    * @throws Exception
    */
   protected function onApiError($entity, $action, $params, $result) {
-    CRM_Core_Error::debug_var('ManagedEntities_failed', array(
+    CRM_Core_Error::debug_var('ManagedEntities_failed', [
       'entity' => $entity,
       'action' => $action,
       'params' => $params,
       'result' => $result,
-    ));
+    ]);
     throw new Exception('API error: ' . $result['error_message']);
   }