From d86fe7b39428a961158c78ce8d35eed91aa22339 Mon Sep 17 00:00:00 2001
From: Aaron Bauman <aaron@messageagency.com>
Date: Mon, 25 Feb 2019 16:13:10 -0500
Subject: [PATCH] Swap auth token manager class for auth token manager
 interface

---
 .../src/Entity/MappedObjectInterface.php      |  2 +-
 .../tests/src/Unit/DeleteHandlerTest.php      |  4 +-
 .../SalesforcePushQueueProcessor/Rest.php     |  8 ++--
 .../salesforce_soap/src/Soap/SoapClient.php   |  8 ++--
 salesforce.install                            |  3 +-
 src/Commands/SalesforceCommandsBase.php       |  8 ++--
 src/Entity/SalesforceAuthConfig.php           |  4 +-
 src/Form/SalesforceAuthSettings.php           |  7 ++-
 src/Rest/RestClient.php                       |  8 ++--
 src/SalesforceAuthProviderPluginManager.php   | 43 ++++---------------
 src/Storage/SalesforceAuthTokenStorage.php    |  2 -
 11 files changed, 33 insertions(+), 64 deletions(-)

diff --git a/modules/salesforce_mapping/src/Entity/MappedObjectInterface.php b/modules/salesforce_mapping/src/Entity/MappedObjectInterface.php
index 44e35d35..2f0d8a34 100644
--- a/modules/salesforce_mapping/src/Entity/MappedObjectInterface.php
+++ b/modules/salesforce_mapping/src/Entity/MappedObjectInterface.php
@@ -62,7 +62,7 @@ interface MappedObjectInterface extends EntityChangedInterface, RevisionLogInter
   /**
    * Wrapper for salesforce auth provider plugin manager.
    *
-   * @return \Drupal\salesforce\SalesforceAuthProviderPluginManager
+   * @return \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
    *   The auth provider plugin manager.
    */
   public function authMan();
diff --git a/modules/salesforce_pull/tests/src/Unit/DeleteHandlerTest.php b/modules/salesforce_pull/tests/src/Unit/DeleteHandlerTest.php
index 5a33700d..71da753a 100644
--- a/modules/salesforce_pull/tests/src/Unit/DeleteHandlerTest.php
+++ b/modules/salesforce_pull/tests/src/Unit/DeleteHandlerTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\salesforce_pull\Unit;
 
 use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
-use Drupal\Core\Entity\Entity;
+use Drupal\Core\Entity\EntityBase;
 use Drupal\Core\Entity\EntityStorageBase;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\State\StateInterface;
@@ -48,7 +48,7 @@ class DeleteHandlerTest extends UnitTestCase {
     $this->sfapi = $prophecy->reveal();
 
     // Mock Drupal entity.
-    $prophecy = $this->prophesize(Entity::CLASS);
+    $prophecy = $this->prophesize(EntityBase::CLASS);
     $prophecy->delete()->willReturn(TRUE);
     $prophecy->id()->willReturn(1);
     $prophecy->label()->willReturn('foo');
diff --git a/modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php b/modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php
index 91f256ae..3d12d739 100644
--- a/modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php
+++ b/modules/salesforce_push/src/Plugin/SalesforcePushQueueProcessor/Rest.php
@@ -2,7 +2,7 @@
 
 namespace Drupal\salesforce_push\Plugin\SalesforcePushQueueProcessor;
 
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
+use Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Plugin\PluginBase;
@@ -65,7 +65,7 @@ class Rest extends PluginBase implements PushQueueProcessorInterface {
   /**
    * Auth manager.
    *
-   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManager
+   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
    */
   protected $authMan;
 
@@ -84,13 +84,13 @@ class Rest extends PluginBase implements PushQueueProcessorInterface {
    *   ETM service.
    * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
    *   Event dispatcher service.
-   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManager $authMan
+   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authMan
    *   Auth manager.
    *
    * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
    * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
-  public function __construct(array $configuration, $plugin_id, array $plugin_definition, PushQueueInterface $queue, EntityTypeManagerInterface $etm, EventDispatcherInterface $eventDispatcher, SalesforceAuthProviderPluginManager $authMan) {
+  public function __construct(array $configuration, $plugin_id, array $plugin_definition, PushQueueInterface $queue, EntityTypeManagerInterface $etm, EventDispatcherInterface $eventDispatcher, SalesforceAuthProviderPluginManagerInterface $authMan) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->queue = $queue;
     $this->etm = $etm;
diff --git a/modules/salesforce_soap/src/Soap/SoapClient.php b/modules/salesforce_soap/src/Soap/SoapClient.php
index 6389c896..bb062985 100644
--- a/modules/salesforce_soap/src/Soap/SoapClient.php
+++ b/modules/salesforce_soap/src/Soap/SoapClient.php
@@ -3,7 +3,7 @@
 namespace Drupal\salesforce_soap\Soap;
 
 use Drupal\salesforce\Rest\RestClientInterface;
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
+use Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface;
 use SforcePartnerClient;
 
 /**
@@ -35,7 +35,7 @@ class SoapClient extends SforcePartnerClient implements SoapClientInterface {
   /**
    * Auth manager.
    *
-   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManager
+   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
    */
   protected $authMan;
 
@@ -44,13 +44,13 @@ class SoapClient extends SforcePartnerClient implements SoapClientInterface {
    *
    * @param \Drupal\salesforce\Rest\RestClientInterface $rest_api
    *   The Salesforce REST API client.
-   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManager $authMan
+   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authMan
    *   Auth manager.
    * @param string $wsdl
    *   (Optional) Path to the WSDL that should be used.  Defaults to using the
    *   partner WSDL from the developerforce/force.com-toolkit-for-php package.
    */
-  public function __construct(RestClientInterface $rest_api, SalesforceAuthProviderPluginManager $authMan, $wsdl = NULL) {
+  public function __construct(RestClientInterface $rest_api, SalesforceAuthProviderPluginManagerInterface $authMan, $wsdl = NULL) {
     parent::__construct();
 
     $this->restApi = $rest_api;
diff --git a/salesforce.install b/salesforce.install
index fbba7123..5907ac99 100644
--- a/salesforce.install
+++ b/salesforce.install
@@ -8,7 +8,6 @@
 use Drupal\Component\Serialization\Json;
 use Drupal\Core\Url;
 use Drupal\salesforce\Entity\SalesforceAuthConfig;
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
 use Drupal\salesforce\Token\SalesforceToken;
 use Drupal\salesforce_oauth\Consumer\SalesforceOAuthCredentials;
 use OAuth\Common\Storage\Exception\TokenNotFoundException;
@@ -66,7 +65,7 @@ function salesforce_get_auth_provider_requirements() {
     'title' => t('Salesforce Authentication Status'),
     'value' => t('Provider Status'),
   ];
-  /** @var \Drupal\salesforce\SalesforceAuthProviderPluginManager $authMan */
+  /** @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authMan */
   $authMan = \Drupal::service('plugin.manager.salesforce.auth_providers');
   if (!$authMan->hasProviders()) {
     $requirements += [
diff --git a/src/Commands/SalesforceCommandsBase.php b/src/Commands/SalesforceCommandsBase.php
index f53ba639..4734cbb7 100644
--- a/src/Commands/SalesforceCommandsBase.php
+++ b/src/Commands/SalesforceCommandsBase.php
@@ -4,7 +4,7 @@ namespace Drupal\salesforce\Commands;
 
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\salesforce\Rest\RestClient;
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
+use Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface;
 use Drupal\salesforce\Storage\SalesforceAuthTokenStorageInterface;
 use Drush\Commands\DrushCommands;
 use Drush\Drush;
@@ -34,7 +34,7 @@ abstract class SalesforceCommandsBase extends DrushCommands {
   /**
    * Salesforce Auth Provider plugin manager service.
    *
-   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManager
+   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
    */
   protected $authMan;
 
@@ -52,7 +52,7 @@ abstract class SalesforceCommandsBase extends DrushCommands {
    *   SF client.
    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $etm
    *   Entity type manager.
-   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManager $authMan
+   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authMan
    *   Auth plugin manager.
    * @param \Drupal\salesforce\Storage\SalesforceAuthTokenStorageInterface $tokenStorage
    *   Token storage.
@@ -60,7 +60,7 @@ abstract class SalesforceCommandsBase extends DrushCommands {
    * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
    * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
-  public function __construct(RestClient $client, EntityTypeManagerInterface $etm, SalesforceAuthProviderPluginManager $authMan, SalesforceAuthTokenStorageInterface $tokenStorage) {
+  public function __construct(RestClient $client, EntityTypeManagerInterface $etm, SalesforceAuthProviderPluginManagerInterface $authMan, SalesforceAuthTokenStorageInterface $tokenStorage) {
     $this->client = $client;
     $this->etm = $etm;
     $this->authMan = $authMan;
diff --git a/src/Entity/SalesforceAuthConfig.php b/src/Entity/SalesforceAuthConfig.php
index a5dd68ae..6377af02 100644
--- a/src/Entity/SalesforceAuthConfig.php
+++ b/src/Entity/SalesforceAuthConfig.php
@@ -66,7 +66,7 @@ class SalesforceAuthConfig extends ConfigEntityBase implements EntityInterface {
   /**
    * Auth manager.
    *
-   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManager
+   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
    */
   protected $manager;
 
@@ -119,7 +119,7 @@ class SalesforceAuthConfig extends ConfigEntityBase implements EntityInterface {
   /**
    * Auth manager wrapper.
    *
-   * @return \Drupal\salesforce\SalesforceAuthProviderPluginManager|mixed
+   * @return \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface|mixed
    *   The auth provider plugin manager.
    */
   public function authManager() {
diff --git a/src/Form/SalesforceAuthSettings.php b/src/Form/SalesforceAuthSettings.php
index 05c0ed34..e5858d87 100644
--- a/src/Form/SalesforceAuthSettings.php
+++ b/src/Form/SalesforceAuthSettings.php
@@ -7,8 +7,7 @@ use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\salesforce\Event\SalesforceEvents;
 use Drupal\salesforce\Event\SalesforceNoticeEvent;
-use Drupal\salesforce\SalesforceAuthManager;
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
+use Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
@@ -25,12 +24,12 @@ class SalesforceAuthSettings extends ConfigFormBase {
    *
    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    *   Config.
-   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManager $salesforceAuth
+   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $salesforceAuth
    *   Authman.
    * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
    *   Events.
    */
-  public function __construct(ConfigFactoryInterface $config_factory, SalesforceAuthProviderPluginManager $salesforceAuth, EventDispatcherInterface $eventDispatcher) {
+  public function __construct(ConfigFactoryInterface $config_factory, SalesforceAuthProviderPluginManagerInterface $salesforceAuth, EventDispatcherInterface $eventDispatcher) {
     parent::__construct($config_factory);
     $this->salesforceAuth = $salesforceAuth;
     $this->eventDispatcher = $eventDispatcher;
diff --git a/src/Rest/RestClient.php b/src/Rest/RestClient.php
index 56d36572..172e34dd 100644
--- a/src/Rest/RestClient.php
+++ b/src/Rest/RestClient.php
@@ -7,7 +7,7 @@ use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\State\StateInterface;
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
+use Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface;
 use Drupal\salesforce\SelectQueryInterface;
 use Drupal\salesforce\SFID;
 use Drupal\salesforce\SObject;
@@ -81,7 +81,7 @@ class RestClient implements RestClientInterface {
   /**
    * Auth provider manager.
    *
-   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManager
+   * @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface
    */
   protected $authManager;
 
@@ -126,10 +126,10 @@ class RestClient implements RestClientInterface {
    *   The JSON serializer service.
    * @param \Drupal\Component\Datetime\TimeInterface $time
    *   The Time service.
-   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManager $authManager
+   * @param \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authManager
    *   Auth manager service.
    */
-  public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, StateInterface $state, CacheBackendInterface $cache, Json $json, TimeInterface $time, SalesforceAuthProviderPluginManager $authManager) {
+  public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, StateInterface $state, CacheBackendInterface $cache, Json $json, TimeInterface $time, SalesforceAuthProviderPluginManagerInterface $authManager) {
     $this->configFactory = $config_factory;
     $this->httpClient = $http_client;
     $this->immutableConfig = $this->configFactory->get('salesforce.settings');
diff --git a/src/SalesforceAuthProviderPluginManager.php b/src/SalesforceAuthProviderPluginManager.php
index 904d14eb..a139e474 100644
--- a/src/SalesforceAuthProviderPluginManager.php
+++ b/src/SalesforceAuthProviderPluginManager.php
@@ -13,7 +13,7 @@ use OAuth\OAuth2\Token\StdOAuth2Token;
 /**
  * Auth provider plugin manager.
  */
-class SalesforceAuthProviderPluginManager extends DefaultPluginManager {
+class SalesforceAuthProviderPluginManager extends DefaultPluginManager implements SalesforceAuthProviderPluginManagerInterface {
 
   /**
    * Config from salesforce.settings.
@@ -73,36 +73,21 @@ class SalesforceAuthProviderPluginManager extends DefaultPluginManager {
   }
 
   /**
-   * All Salesforce auth providers.
-   *
-   * @return \Drupal\salesforce\Entity\SalesforceAuthConfig[]
-   *   All auth provider plugins.
-   *
-   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
-   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
+   * {@inheritdoc}
    */
   public function getProviders() {
     return $this->authStorage()->loadMultiple();
   }
 
   /**
-   * TRUE if any auth providers are defined.
-   *
-   * @return bool
-   *   TRUE if any auth providers are defined.
-   *
-   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
-   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
+   * {@inheritdoc}
    */
   public function hasProviders() {
     return $this->authStorage()->hasData();
   }
 
   /**
-   * Get the active auth service provider, or null if it has not been assigned.
-   *
-   * @return \Drupal\salesforce\Entity\SalesforceAuthConfig|null
-   *   The active service provider, or null if it has not been assigned.
+   * {@inheritdoc}
    */
   public function getConfig() {
     $provider_id = $this->config()->get('salesforce_auth_provider');
@@ -113,10 +98,7 @@ class SalesforceAuthProviderPluginManager extends DefaultPluginManager {
   }
 
   /**
-   * The auth provider plugin of the active service provider, or null.
-   *
-   * @return \Drupal\salesforce\SalesforceAuthProviderInterface|null
-   *   The auth provider plugin of the active service provider, or null.
+   * {@inheritdoc}
    */
   public function getProvider() {
     if (!$this->getConfig()) {
@@ -126,10 +108,7 @@ class SalesforceAuthProviderPluginManager extends DefaultPluginManager {
   }
 
   /**
-   * The credentials for the active auth provider plugin, or null.
-   *
-   * @return \Drupal\salesforce\Consumer\SalesforceCredentialsInterface|null
-   *   The credentials for the active auth provider plugin, or null.
+   * {@inheritdoc}
    */
   public function getCredentials() {
     if (!$this->getProvider()) {
@@ -139,10 +118,7 @@ class SalesforceAuthProviderPluginManager extends DefaultPluginManager {
   }
 
   /**
-   * Get the active token, or null if it has not been assigned.
-   *
-   * @return \OAuth\OAuth2\Token\TokenInterface|null
-   *   The token of the plugin of the active config, or null.
+   * {@inheritdoc}
    */
   public function getToken() {
     if (!$config = $this->getConfig()) {
@@ -160,10 +136,7 @@ class SalesforceAuthProviderPluginManager extends DefaultPluginManager {
   }
 
   /**
-   * Force a refresh of the active token and return the fresh token.
-   *
-   * @return \OAuth\Common\Token\TokenInterface
-   *   The token.
+   * {@inheritdoc}
    */
   public function refreshToken() {
     if (!$config = $this->getConfig()) {
diff --git a/src/Storage/SalesforceAuthTokenStorage.php b/src/Storage/SalesforceAuthTokenStorage.php
index 9cbe5277..c725d918 100644
--- a/src/Storage/SalesforceAuthTokenStorage.php
+++ b/src/Storage/SalesforceAuthTokenStorage.php
@@ -3,8 +3,6 @@
 namespace Drupal\salesforce\Storage;
 
 use Drupal\Core\State\StateInterface;
-use Drupal\salesforce\SalesforceAuthProviderPluginManager;
-use Drupal\salesforce\Token\SalesforceToken;
 use OAuth\Common\Storage\Exception\TokenNotFoundException;
 use OAuth\Common\Token\TokenInterface;
 
-- 
GitLab