From e72ca03bcbfe7ab7d90f62370ade7869449f3fbb Mon Sep 17 00:00:00 2001 From: Ritvik Tak <58260-ritviktak@users.noreply.drupalcode.org> Date: Thu, 30 Nov 2023 10:38:02 -0500 Subject: [PATCH] Issue #3222661 by Ken Patolia, ritviktak, AaronBauman: Coding Standard update --- .../SalesforceExampleSubscriber.php | 64 +++++++++++++++++-- .../SalesforceLoggerSubscriber.php | 7 ++ 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php b/modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php index 5c7f8b2b..fa282f4f 100644 --- a/modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php +++ b/modules/salesforce_example/src/EventSubscriber/SalesforceExampleSubscriber.php @@ -26,6 +26,60 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { use StringTranslationTrait; + /** + * Logger. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + /** + * The Salesforce REST client. + * + * @var \Drupal\salesforce\Rest\RestClientInterface + */ + protected $client; + + /** + * Create a new Salesforce object. + * + * @param \Psr\Log\LoggerInterface $logger + * The logger. + * @param \Drupal\salesforce\Rest\RestClientInterface $salesforce_client + * The factory for configuration objects. + */ + public function __construct(LoggerInterface $logger, RestClientInterface $salesforce_client) { + $this->logger = $logger; + $this->client = $salesforce_client; + } + + /** + * Logger. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + /** + * The Salesforce REST client. + * + * @var \Drupal\salesforce\Rest\RestClientInterface + */ + protected $client; + + /** + * Create a new Salesforce object. + * + * @param \Psr\Log\LoggerInterface $logger + * The logger. + * @param \Drupal\salesforce\Rest\RestClientInterface $salesforce_client + * The factory for configuration objects. + */ + public function __construct(LoggerInterface $logger, RestClientInterface $salesforce_client) { + $this->logger = $logger; + $this->client = $salesforce_client; + } + /** * SalesforcePushAllowedEvent callback. * @@ -81,7 +135,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { // Do Y. break; } - \Drupal::messenger()->addStatus('push success example subscriber!: ' . $event->getMappedObject()->sfid()); + $this->messenger->addStatus('push success example subscriber!: ' . $event->getMappedObject()->sfid()); } /** @@ -91,7 +145,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { * The event. */ public function pushFail(SalesforcePushOpEvent $event) { - \Drupal::messenger()->addStatus('push fail example: ' . $event->getMappedObject()->id()); + $this->messenger->addStatus('push fail example: ' . $event->getMappedObject()->id()); } /** @@ -133,7 +187,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { // Attachment data, if given. $account = $event->getEntity(); $sf_data = $event->getMappedObject()->getSalesforceRecord(); - $client = \Drupal::service('salesforce.client'); + $client = $this->client; // Fetch the attachment URL from raw sf data. $attachments = []; try { @@ -158,7 +212,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { } catch (\Exception $e) { // Unable to fetch file data from SF. - \Drupal::logger('db')->error($this->t('failed to fetch attachment for user @user', ['@user' => $account->id()])); + $this->logger('db')->error($this->t('failed to fetch attachment for user @user', ['@user' => $account->id()])); return; } @@ -171,7 +225,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface { $account->user_picture->target_id = $file->id(); } else { - \Drupal::logger('db')->error('failed to save profile pic for user ' . $account->id()); + $this->logger('db')->error('failed to save profile pic for user ' . $account->id()); } break; diff --git a/modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php b/modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php index f41bf8b6..f60cca3a 100644 --- a/modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php +++ b/modules/salesforce_logger/src/EventSubscriber/SalesforceLoggerSubscriber.php @@ -26,6 +26,13 @@ class SalesforceLoggerSubscriber implements EventSubscriberInterface { */ protected $logger; + /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + /** * Create a new Salesforce Logger Subscriber. * -- GitLab