CIVICRM-1223 fix errors
[civicrm-core.git] / CRM / Core / BAO / RecurringEntity.php
index 3dfec02e659ffedbf715dfc1e6602537072d4759..a74f8ca35e8ed5846db846d55aa8b2d1af50bfdb 100644 (file)
@@ -31,7 +31,7 @@
  * @copyright CiviCRM LLC (c) 2004-2019
  */
 
-require_once 'packages/When/When.php';
+use When\When;
 
 /**
  * Class CRM_Core_BAO_RecurringEntity.
@@ -39,54 +39,54 @@ require_once 'packages/When/When.php';
 class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
 
   const RUNNING = 1;
-  public $schedule = array();
+  public $schedule = [];
   public $scheduleId = NULL;
-  public $scheduleFormValues = array();
+  public $scheduleFormValues = [];
 
-  public $dateColumns = array();
-  public $overwriteColumns = array();
-  public $intervalDateColumns = array();
-  public $excludeDates = array();
+  public $dateColumns = [];
+  public $overwriteColumns = [];
+  public $intervalDateColumns = [];
+  public $excludeDates = [];
 
-  public $linkedEntities = array();
+  public $linkedEntities = [];
 
   public $isRecurringEntityRecord = TRUE;
 
   protected $recursion = NULL;
   protected $recursion_start_date = NULL;
 
-  public static $_entitiesToBeDeleted = array();
+  public static $_entitiesToBeDeleted = [];
 
   public static $status = NULL;
 
-  static $_recurringEntityHelper
-    = array(
-      'civicrm_event' => array(
+  public static $_recurringEntityHelper
+    = [
+      'civicrm_event' => [
         'helper_class' => 'CRM_Event_DAO_Event',
         'delete_func' => 'delete',
         'pre_delete_func' => 'CRM_Event_Form_ManageEvent_Repeat::checkRegistrationForEvents',
-      ),
-      'civicrm_activity' => array(
+      ],
+      'civicrm_activity' => [
         'helper_class' => 'CRM_Activity_DAO_Activity',
         'delete_func' => 'delete',
         'pre_delete_func' => '',
-      ),
-    );
-
-  static $_dateColumns
-    = array(
-      'civicrm_event' => array(
-        'dateColumns' => array('start_date'),
-        'excludeDateRangeColumns' => array('start_date', 'end_date'),
-        'intervalDateColumns' => array('end_date'),
-      ),
-      'civicrm_activity' => array(
-        'dateColumns' => array('activity_date_time'),
-      ),
-    );
-
-  static $_tableDAOMapper
-    = array(
+      ],
+    ];
+
+  public static $_dateColumns
+    = [
+      'civicrm_event' => [
+        'dateColumns' => ['start_date'],
+        'excludeDateRangeColumns' => ['start_date', 'end_date'],
+        'intervalDateColumns' => ['end_date'],
+      ],
+      'civicrm_activity' => [
+        'dateColumns' => ['activity_date_time'],
+      ],
+    ];
+
+  public static $_tableDAOMapper
+    = [
       'civicrm_event' => 'CRM_Event_DAO_Event',
       'civicrm_price_set_entity' => 'CRM_Price_DAO_PriceSetEntity',
       'civicrm_uf_join' => 'CRM_Core_DAO_UFJoin',
@@ -94,37 +94,37 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock',
       'civicrm_activity' => 'CRM_Activity_DAO_Activity',
       'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
-    );
-
-  static $_updateSkipFields
-    = array(
-      'civicrm_event' => array('start_date', 'end_date'),
-      'civicrm_tell_friend' => array('entity_id'),
-      'civicrm_pcp_block' => array('entity_id'),
-      'civicrm_activity' => array('activity_date_time'),
-    );
-
-  static $_linkedEntitiesInfo
-    = array(
-      'civicrm_tell_friend' => array(
+    ];
+
+  public static $_updateSkipFields
+    = [
+      'civicrm_event' => ['start_date', 'end_date'],
+      'civicrm_tell_friend' => ['entity_id'],
+      'civicrm_pcp_block' => ['entity_id'],
+      'civicrm_activity' => ['activity_date_time'],
+    ];
+
+  public static $_linkedEntitiesInfo
+    = [
+      'civicrm_tell_friend' => [
         'entity_id_col' => 'entity_id',
         'entity_table_col' => 'entity_table',
-      ),
-      'civicrm_price_set_entity' => array(
+      ],
+      'civicrm_price_set_entity' => [
         'entity_id_col' => 'entity_id',
         'entity_table_col' => 'entity_table',
         'is_multirecord' => TRUE,
-      ),
-      'civicrm_uf_join' => array(
+      ],
+      'civicrm_uf_join' => [
         'entity_id_col' => 'entity_id',
         'entity_table_col' => 'entity_table',
         'is_multirecord' => TRUE,
-      ),
-      'civicrm_pcp_block' => array(
+      ],
+      'civicrm_pcp_block' => [
         'entity_id_col' => 'entity_id',
         'entity_table_col' => 'entity_table',
-      ),
-    );
+      ],
+    ];
 
   //Define global CLASS CONSTANTS for recurring entity mode types
   const MODE_THIS_ENTITY_ONLY = 1;
@@ -194,11 +194,11 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    */
   public static function quickAdd($parentId, $entityId, $entityTable) {
     $params
-      = array(
+      = [
         'parent_id' => $parentId,
         'entity_id' => $entityId,
         'entity_table' => $entityTable,
-      );
+      ];
     return self::add($params);
   }
 
@@ -266,11 +266,11 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
   public function generateEntities() {
     self::setStatus(self::RUNNING);
 
-    $newEntities = array();
-    $findCriteria = array();
+    $newEntities = [];
+    $findCriteria = [];
     if (!empty($this->recursionDates)) {
       if ($this->entity_id) {
-        $findCriteria = array('id' => $this->entity_id);
+        $findCriteria = ['id' => $this->entity_id];
 
         // save an entry with initiating entity-id & entity-table
         if ($this->entity_table && !$this->find(TRUE)) {
@@ -296,7 +296,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
         );
 
         if (is_a($obj, 'CRM_Core_DAO') && $obj->id) {
-          $newCriteria = array();
+          $newCriteria = [];
           $newEntities[$this->entity_table][$count] = $obj->id;
 
           foreach ($this->linkedEntities as $linkedInfo) {
@@ -333,8 +333,8 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
   public function generateRecursiveDates() {
     $this->generateRecursion();
 
-    $recursionDates = array();
-    if (is_a($this->recursion, 'When')) {
+    $recursionDates = [];
+    if (is_a($this->recursion, 'When\When')) {
       $initialCount = CRM_Utils_Array::value('start_action_offset', $this->schedule);
 
       $exRangeStart = $exRangeEnd = NULL;
@@ -344,12 +344,15 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       }
 
       $count = 1;
-      while ($result = $this->recursion->next()) {
-        $skip = FALSE;
-        if ($result == $this->recursion_start_date) {
-          // skip the recursion-start-date from the list we going to generate
-          $skip = TRUE;
-        }
+      try {
+        $this->recursion->RFC5545_COMPLIANT = When::IGNORE;
+        $this->recursion->generateOccurrences();
+      }
+      catch (Exception $e) {
+        CRM_Core_Session::setStatus(ts($e->getMessage()));
+        return $recursionDates;
+      }
+      foreach ($this->recursion->occurrences as $result) {
         $baseDate = $result->format('YmdHis');
 
         foreach ($this->dateColumns as $col) {
@@ -383,15 +386,6 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
           }
         }
 
-        if ($skip) {
-          unset($recursionDates[$count]);
-          if ($initialCount && ($initialCount > 0)) {
-            // lets increase the counter, so we get correct number of occurrences
-            $initialCount++;
-            $this->recursion->count($initialCount);
-          }
-          continue;
-        }
         $count++;
       }
     }
@@ -418,8 +412,8 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return array
    *   an array of child ids
    */
-  static public function getEntitiesForParent($parentId, $entityTable, $includeParent = TRUE, $mode = 3, $initiatorId = NULL) {
-    $entities = array();
+  public static function getEntitiesForParent($parentId, $entityTable, $includeParent = TRUE, $mode = 3, $initiatorId = NULL) {
+    $entities = [];
     if (empty($parentId) || empty($entityTable)) {
       return $entities;
     }
@@ -428,11 +422,11 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       $initiatorId = $parentId;
     }
 
-    $queryParams = array(
-      1 => array($parentId, 'Integer'),
-      2 => array($entityTable, 'String'),
-      3 => array($initiatorId, 'Integer'),
-    );
+    $queryParams = [
+      1 => [$parentId, 'Integer'],
+      2 => [$entityTable, 'String'],
+      3 => [$initiatorId, 'Integer'],
+    ];
 
     if (!$mode) {
       $mode = CRM_Core_DAO::singleValueQuery("SELECT mode FROM civicrm_recurring_entity WHERE entity_id = %3 AND entity_table = %2", $queryParams);
@@ -454,12 +448,13 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       $recurringEntityID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_recurring_entity WHERE entity_id = %3 AND entity_table = %2", $queryParams);
       if ($recurringEntityID) {
         $query .= $includeParent ? " AND id >= %4" : " AND id > %4";
-        $query .= " ORDER BY id ASC"; // FIXME: change to order by dates
-        $queryParams[4] = array($recurringEntityID, 'Integer');
+        // FIXME: change to order by dates
+        $query .= " ORDER BY id ASC";
+        $queryParams[4] = [$recurringEntityID, 'Integer'];
       }
       else {
         // something wrong, return empty
-        return array();
+        return [];
       }
     }
 
@@ -488,12 +483,12 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return array
    *   array of connected ids
    */
-  static public function getEntitiesFor($entityId, $entityTable, $includeParent = TRUE, $mode = 3) {
+  public static function getEntitiesFor($entityId, $entityTable, $includeParent = TRUE, $mode = 3) {
     $parentId = self::getParentFor($entityId, $entityTable);
     if ($parentId) {
       return self::getEntitiesForParent($parentId, $entityTable, $includeParent, $mode, $entityId);
     }
-    return array();
+    return [];
   }
 
   /**
@@ -510,7 +505,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return int
    *   unsigned $parentId Parent ID
    */
-  static public function getParentFor($entityId, $entityTable, $includeParent = TRUE) {
+  public static function getParentFor($entityId, $entityTable, $includeParent = TRUE) {
     if (empty($entityId) || empty($entityTable)) {
       return NULL;
     }
@@ -524,10 +519,10 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
     }
     $parentId
       = CRM_Core_DAO::singleValueQuery($query,
-        array(
-          1 => array($entityId, 'Integer'),
-          2 => array($entityTable, 'String'),
-        )
+        [
+          1 => [$entityId, 'Integer'],
+          2 => [$entityTable, 'String'],
+        ]
       );
     return $parentId;
   }
@@ -539,7 +534,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @param $entityTable
    * @return array|null
    */
-  static public function getPositionAndCount($entityId, $entityTable) {
+  public static function getPositionAndCount($entityId, $entityTable) {
     $position = $count = 0;
 
     $query = "
@@ -548,10 +543,10 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       WHERE parent_id = (SELECT parent_id FROM civicrm_recurring_entity WHERE entity_id = %1 AND entity_table = %2) AND entity_table = %2";
 
     $dao = CRM_Core_DAO::executeQuery($query,
-      array(
-        1 => array($entityId, 'Integer'),
-        2 => array($entityTable, 'String'),
-      )
+      [
+        1 => [$entityId, 'Integer'],
+        2 => [$entityTable, 'String'],
+      ]
     );
 
     while ($dao->fetch()) {
@@ -561,7 +556,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       }
     }
     if ($count) {
-      return array($position, $count);
+      return [$position, $count];
     }
     return NULL;
   }
@@ -581,7 +576,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    *
    * @return object
    */
-  static public function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE) {
+  public static function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE) {
     $daoName = self::$_tableDAOMapper[$entityTable];
     if (!$daoName) {
       CRM_Core_Error::fatal("DAO Mapper missing for $entityTable.");
@@ -608,7 +603,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @param object $event
    *   An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just updated.
    */
-  static public function triggerUpdate($event) {
+  public static function triggerUpdate($event) {
     // if DB version is earlier than 4.6 skip any processing
     static $currentVer = NULL;
     if (!$currentVer) {
@@ -618,7 +613,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       return;
     }
 
-    static $processedEntities = array();
+    static $processedEntities = [];
     $obj =& $event->object;
     if (empty($obj->id) || empty($obj->__table)) {
       return;
@@ -651,7 +646,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       if (array_key_exists($entityTable, self::$_tableDAOMapper)) {
         $daoName = self::$_tableDAOMapper[$entityTable];
 
-        $skipData = array();
+        $skipData = [];
         if (array_key_exists($entityTable, self::$_updateSkipFields)) {
           $skipFields = self::$_updateSkipFields[$entityTable];
           foreach ($skipFields as $sfield) {
@@ -676,7 +671,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @param object $event
    *   An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just inserted.
    */
-  static public function triggerInsert($event) {
+  public static function triggerInsert($event) {
     $obj =& $event->object;
     if (!array_key_exists($obj->__table, self::$_linkedEntitiesInfo)) {
       return;
@@ -691,7 +686,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       return;
     }
 
-    static $processedEntities = array();
+    static $processedEntities = [];
     if (empty($obj->id) || empty($obj->__table)) {
       return;
     }
@@ -754,12 +749,12 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
               }
               else {
                 // linked entity doesn't exist. lets create them
-                $newCriteria = array(
+                $newCriteria = [
                   $idCol => $val['id'],
                   $tableCol => $val['table'],
-                );
+                ];
                 $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($obj->__table,
-                  array('id' => $obj->id),
+                  ['id' => $obj->id],
                   $newCriteria,
                   TRUE
                 );
@@ -783,7 +778,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @param object $event
    *   An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just deleted.
    */
-  static public function triggerDelete($event) {
+  public static function triggerDelete($event) {
     $obj =& $event->object;
 
     // if DB version is earlier than 4.6 skip any processing
@@ -795,7 +790,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       return;
     }
 
-    static $processedEntities = array();
+    static $processedEntities = [];
     if (empty($obj->id) || empty($obj->__table) || !$event->result) {
       return;
     }
@@ -828,7 +823,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return bool|\CRM_Core_DAO_RecurringEntity
    * @throws \Exception
    */
-  static public function delEntity($entityId, $entityTable, $isDelLinkedEntities = FALSE) {
+  public static function delEntity($entityId, $entityTable, $isDelLinkedEntities = FALSE) {
     if (empty($entityId) || empty($entityTable)) {
       return FALSE;
     }
@@ -868,8 +863,8 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    *
    * @return array
    */
-  public function mapFormValuesToDB($formParams = array()) {
-    $dbParams = array();
+  public function mapFormValuesToDB($formParams = []) {
+    $dbParams = [];
     if (!empty($formParams['used_for'])) {
       $dbParams['used_for'] = $formParams['used_for'];
     }
@@ -916,7 +911,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
         }
       }
       if ($formParams['repeats_by'] == 2) {
-        if (CRM_Utils_Array::value('entity_status_1', $formParams) && CRM_Utils_Array::value('entity_status_2', $formParams)) {
+        if (!empty($formParams['entity_status_1']) && !empty($formParams['entity_status_2'])) {
           $dbParams['entity_status'] = $formParams['entity_status_1'] . " " . $formParams['entity_status_2'];
         }
       }
@@ -947,7 +942,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    *
    * @return object
    */
-  static public function getScheduleReminderDetailsById($scheduleReminderId) {
+  public static function getScheduleReminderDetailsById($scheduleReminderId) {
     $query = "SELECT *
       FROM civicrm_action_schedule WHERE 1";
     if ($scheduleReminderId) {
@@ -955,9 +950,9 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
         AND id = %1";
     }
     $dao = CRM_Core_DAO::executeQuery($query,
-      array(
-        1 => array($scheduleReminderId, 'Integer'),
-      )
+      [
+        1 => [$scheduleReminderId, 'Integer'],
+      ]
     );
     $dao->fetch();
     return $dao;
@@ -972,7 +967,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return array
    */
   public function getScheduleParams($scheduleReminderId) {
-    $scheduleReminderDetails = array();
+    $scheduleReminderDetails = [];
     if ($scheduleReminderId) {
       //Get all the details from schedule reminder table
       $scheduleReminderDetails = self::getScheduleReminderDetailsById($scheduleReminderId);
@@ -991,7 +986,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return object
    *   When object
    */
-  public function getRecursionFromSchedule($scheduleReminderDetails = array()) {
+  public function getRecursionFromSchedule($scheduleReminderDetails = []) {
     $r = new When();
     //If there is some data for this id
     if ($scheduleReminderDetails['repetition_frequency_unit']) {
@@ -1009,7 +1004,9 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
           $repetition_frequency_unit = "dai";
         }
         $repetition_frequency_unit = $repetition_frequency_unit . 'ly';
-        $r->recur($start, $repetition_frequency_unit);
+        $r->startDate($start)
+          ->exclusions([$start])
+          ->freq($repetition_frequency_unit);
       }
 
       if ($scheduleReminderDetails['repetition_frequency_interval']) {
@@ -1024,7 +1021,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
         if ($scheduleReminderDetails['start_action_condition']) {
           $startActionCondition = $scheduleReminderDetails['start_action_condition'];
           $explodeStartActionCondition = explode(',', $startActionCondition);
-          $buildRuleArray = array();
+          $buildRuleArray = [];
           foreach ($explodeStartActionCondition as $key => $val) {
             $buildRuleArray[] = strtoupper(substr($val, 0, 2));
           }
@@ -1058,10 +1055,10 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
               break;
           }
           $concatStartActionDateBits = $startActionDate1 . strtoupper(substr($startActionDate[1], 0, 2));
-          $r->byday(array($concatStartActionDateBits));
+          $r->byday([$concatStartActionDateBits]);
         }
         elseif ($scheduleReminderDetails['limit_to']) {
-          $r->bymonthday(array($scheduleReminderDetails['limit_to']));
+          $r->bymonthday([$scheduleReminderDetails['limit_to']]);
         }
       }
 
@@ -1091,7 +1088,6 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
     return $r;
   }
 
-
   /**
    * This function gets time difference between the two datetime object.
    *
@@ -1104,7 +1100,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return object
    *   DateTime object which contain time difference
    */
-  static public function getInterval($startDate, $endDate) {
+  public static function getInterval($startDate, $endDate) {
     if ($startDate && $endDate) {
       $startDate = new DateTime($startDate);
       $endDate = new DateTime($endDate);
@@ -1132,10 +1128,10 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       if ($used_for) {
         $query .= " AND used_for = %2";
       }
-      $params = array(
-        1 => array($entityId, 'Integer'),
-        2 => array($used_for, 'String'),
-      );
+      $params = [
+        1 => [$entityId, 'Integer'],
+        2 => [$used_for, 'String'],
+      ];
       $dao = CRM_Core_DAO::executeQuery($query, $params);
       $dao->fetch();
     }
@@ -1154,7 +1150,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return array
    */
   public static function updateModeLinkedEntity($entityId, $linkedEntityTable, $mainEntityTable) {
-    $result = array();
+    $result = [];
     if ($entityId && $linkedEntityTable && $mainEntityTable) {
       if (CRM_Utils_Array::value($linkedEntityTable, self::$_tableDAOMapper)) {
         $dao = self::$_tableDAOMapper[$linkedEntityTable];
@@ -1164,11 +1160,11 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
         return NULL;
       }
       $entityTable = $linkedEntityTable;
-      $params = array(
+      $params = [
         'entity_id' => $entityId,
         'entity_table' => $mainEntityTable,
-      );
-      $defaults = array();
+      ];
+      $defaults = [];
       CRM_Core_DAO::commonRetrieve($dao, $params, $defaults);
       if (!empty($defaults['id'])) {
         $result['entityId'] = $defaults['id'];
@@ -1193,7 +1189,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return array
    */
   public static function updateModeAndPriceSet($entityId, $entityTable, $mode, $linkedEntityTable, $priceSet) {
-    $finalResult = array();
+    $finalResult = [];
 
     if (!empty($linkedEntityTable)) {
       $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $linkedEntityTable, $entityTable);
@@ -1222,10 +1218,12 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
           $seriesEventRecords = CRM_Core_BAO_RecurringEntity::getEntitiesFor($entityId, $entityTable);
           foreach ($seriesEventRecords as $event) {
             //Step-2: Save price set in other series events
-            if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {//Remove existing priceset
+            //Remove existing priceset
+            if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {
               CRM_Core_BAO_Discount::del($event['id'], $event['table']);
             }
-            CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet); //Add new price set
+            //Add new price set
+            CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet);
           }
         }
 
@@ -1235,10 +1233,12 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
           foreach ($seriesEventRecords as $event) {
             //Step-2: Save price set in other series events
             if ($entityId < $event["id"]) {
-              if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {//Remove existing priceset
+              //Remove existing priceset
+              if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {
                 CRM_Core_BAO_Discount::del($event['id'], $event['table']);
               }
-              CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet); //Add new price set
+              //Add new price set
+              CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet);
             }
           }
         }