From 385d8c8e1aabe01ee964a8ab82b6938c7794fc64 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 17 Jan 2022 18:29:23 +1300 Subject: [PATCH] More comments & style fixes This is mostly generated by code sniffer but I also added the deprecation to the isEnvironment function as I wound up having to do cleanup on something never called.... --- CRM/Core/BAO/Setting.php | 31 ++++++++++--------- CRM/Utils/System/Backdrop.php | 3 +- CRM/Utils/System/DrupalBase.php | 3 +- .../docs/develop/CheckSendableEvent.md | 5 ++- .../docs/develop/ComposeBatchEvent.md | 9 ++++-- ext/flexmailer/docs/develop/RunEvent.md | 1 + ext/flexmailer/docs/develop/SendBatchEvent.md | 6 ++-- .../docs/develop/WalkBatchesEvent.md | 4 ++- 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/CRM/Core/BAO/Setting.php b/CRM/Core/BAO/Setting.php index ac9b1309b1..077a1cb0b1 100644 --- a/CRM/Core/BAO/Setting.php +++ b/CRM/Core/BAO/Setting.php @@ -125,7 +125,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * Store an item in the setting table. * - * @param $value + * @param mixed $value * (required) The value that will be serialized and stored. * @param string $group * The group name of the item (deprecated). @@ -247,7 +247,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { $getFieldsParams = ['version' => 3]; if (count($settingParams) == 1) { // ie we are only setting one field - we'll pass it into getfields for efficiency - list($name) = array_keys($settingParams); + [$name] = array_keys($settingParams); $getFieldsParams['name'] = $name; } $fields = civicrm_api3('setting', 'getfields', $getFieldsParams); @@ -420,9 +420,10 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { } /** - * @param $group (deprecated) + * @param string $group + * Deprecated parameter * @param string $name - * @param $value + * @param mixed $value * @param bool $system * @param int $userID * @param string $keyField @@ -472,24 +473,26 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { /** * Check if environment is explicitly set. * + * @param $setting + * * @return bool */ - public static function isEnvironmentSet($setting, $value = NULL) { + public static function isEnvironmentSet($setting): bool { + CRM_Core_Error::deprecatedFunctionWarning('no alternative'); $environment = CRM_Core_Config::environment(); - if ($setting == 'environment' && $environment) { - return TRUE; - } - return FALSE; + return $setting === 'environment' && $environment; } /** * Check if job is able to be executed by API. * - * @throws API_Exception + * @param $params + * + * @throws \CRM_Core_Exception */ - public static function isAPIJobAllowedToRun($params) { + public static function isAPIJobAllowedToRun($params): void { $environment = CRM_Core_Config::environment(NULL, TRUE); - if ($environment != 'Production') { + if ($environment !== 'Production') { if (!empty($params['runInNonProductionEnvironment'])) { $mailing = Civi::settings()->get('mailing_backend_store'); if ($mailing) { @@ -497,7 +500,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { } } else { - throw new Exception(ts("Job has not been executed as it is a %1 (non-production) environment.", [1 => $environment])); + throw new CRM_Core_Exception(ts('Job has not been executed as it is a %1 (non-production) environment.', [1 => $environment])); } } } @@ -515,7 +518,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting { * Specification of the setting (per *.settings.php). */ public static function onChangeEnvironmentSetting($oldValue, $newValue, $metadata) { - if ($newValue != 'Production') { + if ($newValue !== 'Production') { $mailing = Civi::settings()->get('mailing_backend'); if ($mailing['outBound_option'] != CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) { Civi::settings()->set('mailing_backend_store', $mailing); diff --git a/CRM/Utils/System/Backdrop.php b/CRM/Utils/System/Backdrop.php index 692669e82f..8dbf872783 100644 --- a/CRM/Utils/System/Backdrop.php +++ b/CRM/Utils/System/Backdrop.php @@ -920,7 +920,8 @@ AND u.status = 1 /** * Check if a resource url is within the Backdrop directory and format appropriately. * - * @param $url (reference) + * @param string $url + * URL (reference). * * @return bool * TRUE for internal paths, FALSE for external. The backdrop_add_js fn is able to add js more diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 075f9d973e..b25d6fc823 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -89,7 +89,8 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { /** * Check if a resource url is within the drupal directory and format appropriately. * - * @param $url (reference) + * @param string $url + * URL (reference). * * @return bool * TRUE for internal paths, FALSE for external. The drupal_add_js fn is able to add js more diff --git a/ext/flexmailer/docs/develop/CheckSendableEvent.md b/ext/flexmailer/docs/develop/CheckSendableEvent.md index a36d83f58c..be73ee09a7 100644 --- a/ext/flexmailer/docs/develop/CheckSendableEvent.md +++ b/ext/flexmailer/docs/develop/CheckSendableEvent.md @@ -20,10 +20,13 @@ function mustache_civicrm_container($container) { } function _mustache_check_sendable(\Civi\FlexMailer\Event\CheckSendableEvent $e) { - if ($e->getMailing()->template_type !== 'mustache') return; + if ($e->getMailing()->template_type !== 'mustache') { + return; + } if (strpos('{{unsubscribeUrl}}', $e->getMailing()->body_html) === FALSE) { $e->setError('body_html:unsubscribeUrl', E::ts('Please include the token {{unsubscribeUrl}}')); } } + ``` diff --git a/ext/flexmailer/docs/develop/ComposeBatchEvent.md b/ext/flexmailer/docs/develop/ComposeBatchEvent.md index 80bd17cc58..e19d3e892b 100644 --- a/ext/flexmailer/docs/develop/ComposeBatchEvent.md +++ b/ext/flexmailer/docs/develop/ComposeBatchEvent.md @@ -31,11 +31,15 @@ function mustache_civicrm_container($container) { } function _mustache_compose_batch(\Civi\FlexMailer\Event\ComposeBatchEvent $event) { - if ($event->getMailing()->template_type !== 'mustache') return; + if ($event->getMailing()->template_type !== 'mustache') { + return; + } $m = new Mustache_Engine(); foreach ($event->getTasks() as $task) { - if ($task->hasContent()) continue; + if ($task->hasContent()) { + continue; + } $contact = civicrm_api3('Contact', 'getsingle', array( 'id' => $task->getContactId(), )); @@ -43,6 +47,7 @@ function _mustache_compose_batch(\Civi\FlexMailer\Event\ComposeBatchEvent $event $task->setMailParam('html', $m->render($event->getMailing()->body_html, $contact)); } } + ``` This implementation is naive in a few ways -- it performs separate SQL queries for each recipient; it doesn't optimize diff --git a/ext/flexmailer/docs/develop/RunEvent.md b/ext/flexmailer/docs/develop/RunEvent.md index a4fa5d25e0..289d466925 100644 --- a/ext/flexmailer/docs/develop/RunEvent.md +++ b/ext/flexmailer/docs/develop/RunEvent.md @@ -28,6 +28,7 @@ function example_civicrm_container($container) { function _example_run(\Civi\FlexMailer\Event\RunEvent $event) { printf("Starting work on job #%d for mailing #%d\n", $event->getJob()->id, $event->getMailing()->id); } + ``` !!! note "Stopping the `RunEvent` will stop FlexMailer." diff --git a/ext/flexmailer/docs/develop/SendBatchEvent.md b/ext/flexmailer/docs/develop/SendBatchEvent.md index dcba869b0b..0b88c36b59 100644 --- a/ext/flexmailer/docs/develop/SendBatchEvent.md +++ b/ext/flexmailer/docs/develop/SendBatchEvent.md @@ -11,7 +11,8 @@ function example_civicrm_container($container) { } function _example_send_batch(\Civi\FlexMailer\Event\SendBatchEvent $event) { - $event->stopPropagation(); // Disable standard delivery + // Disable standard delivery + $event->stopPropagation(); $context = stream_context_create(array( 'http' => array( @@ -20,6 +21,7 @@ function _example_send_batch(\Civi\FlexMailer\Event\SendBatchEvent $event) { 'content' => serialize($event->getTasks()), ), )); - return file_get_contents('https://example.org/batch-delivery', false, $context); + return file_get_contents('https://example.org/batch-delivery', FALSE, $context); } + ``` diff --git a/ext/flexmailer/docs/develop/WalkBatchesEvent.md b/ext/flexmailer/docs/develop/WalkBatchesEvent.md index 346aefdc7d..9703344bb0 100644 --- a/ext/flexmailer/docs/develop/WalkBatchesEvent.md +++ b/ext/flexmailer/docs/develop/WalkBatchesEvent.md @@ -13,7 +13,8 @@ function example_civicrm_container($container) { } function _example_walk_batches(\Civi\FlexMailer\Event\WalkBatchesEvent $event) { - $event->stopPropagation(); // Disable standard delivery + // Disable standard delivery + $event->stopPropagation(); while (...) { $tasks = array(); @@ -23,4 +24,5 @@ function _example_walk_batches(\Civi\FlexMailer\Event\WalkBatchesEvent $event) { $event->visit($tasks); } } + ``` -- 2.25.1