From b65ed71e515c12cbaed85d975d585ebf8bf4705e Mon Sep 17 00:00:00 2001
From: Aaron Bauman <aaron@messageagency.com>
Date: Thu, 29 Nov 2018 13:47:44 -0500
Subject: [PATCH] Documentation standards updates

---
 .../src/Form/SalesforceMappingFormBase.php    |   2 +-
 src/Controller/SalesforceController.php       |  15 +-
 src/EntityNotFoundException.php               |  55 ++++--
 src/Form/AuthorizeForm.php                    |  36 ++--
 src/Form/RevokeAuthorizationForm.php          |  20 +--
 src/Form/SettingsForm.php                     |  11 +-
 src/Rest/RestClient.php                       |  19 +-
 src/Rest/RestClientInterface.php              |   4 +-
 src/Rest/RestException.php                    |  28 ++-
 src/Rest/RestResponse.php                     |  10 +-
 src/Rest/RestResponseDescribe.php             | 167 ++++++++++++++++++
 src/Rest/RestResponseResources.php            |  36 ++++
 src/Rest/RestResponse_Describe.php            | 151 +---------------
 src/Rest/RestResponse_Resources.php           |  29 +--
 src/SFID.php                                  |   6 +-
 src/SObject.php                               |  16 +-
 src/SelectQueryInterface.php                  |   2 +-
 src/SelectQueryRaw.php                        |   2 +-
 src/SelectQueryResult.php                     |  27 ++-
 src/Tests/SalesforceAdminSettingsTest.php     |   2 +-
 src/Tests/TestHttpClient.php                  |   2 +
 src/Tests/TestRestClient.php                  | Bin 236314 -> 236313 bytes
 tests/src/Unit/RestClientTest.php             |   8 +-
 23 files changed, 394 insertions(+), 254 deletions(-)
 create mode 100644 src/Rest/RestResponseDescribe.php
 create mode 100644 src/Rest/RestResponseResources.php

diff --git a/modules/salesforce_mapping/src/Form/SalesforceMappingFormBase.php b/modules/salesforce_mapping/src/Form/SalesforceMappingFormBase.php
index 234c244a..9788b132 100644
--- a/modules/salesforce_mapping/src/Form/SalesforceMappingFormBase.php
+++ b/modules/salesforce_mapping/src/Form/SalesforceMappingFormBase.php
@@ -66,7 +66,7 @@ abstract class SalesforceMappingFormBase extends EntityForm {
    * @param string $salesforce_object_type
    *   The object type of whose records you want to retreive.
    *
-   * @return RestResponse_Describe
+   * @return \Drupal\salesforce\Rest\RestResponseDescribe
    *   Information about the Salesforce object as provided by Salesforce.
    *
    * @throws Exception if $salesforce_object_type is not provided and
diff --git a/src/Controller/SalesforceController.php b/src/Controller/SalesforceController.php
index e94e601b..9fb2133d 100644
--- a/src/Controller/SalesforceController.php
+++ b/src/Controller/SalesforceController.php
@@ -12,19 +12,19 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
 
 /**
- *
+ * OAuth callback handler.
  */
 class SalesforceController extends ControllerBase {
 
   protected $client;
-  protected $http_client;
+  protected $httpClient;
 
   /**
    * {@inheritdoc}
    */
-  public function __construct(RestClientInterface $rest, Client $http_client, MetadataBubblingUrlGenerator $url_generator) {
+  public function __construct(RestClientInterface $rest, Client $httpClient, MetadataBubblingUrlGenerator $url_generator) {
     $this->client = $rest;
-    $this->http_client = $http_client;
+    $this->httpClient = $httpClient;
     $this->url_generator = $url_generator;
   }
 
@@ -40,14 +40,17 @@ class SalesforceController extends ControllerBase {
   }
 
   /**
+   * Wrapper for \Drupal::request().
    *
+   * @return \Symfony\Component\HttpFoundation\Request
+   *   The currently active request object.
    */
   protected function request() {
     return \Drupal::request();
   }
 
   /**
-   *
+   * Display a success message on successful oauth.
    */
   protected function successMessage() {
     drupal_set_message(t('Successfully connected to %endpoint', ['%endpoint' => $this->client->getInstanceUrl()]));
@@ -78,7 +81,7 @@ class SalesforceController extends ControllerBase {
       'Content-Type' => 'application/x-www-form-urlencoded',
     ];
 
-    $response = $this->http_client->post($url, ['headers' => $headers, 'body' => $data]);
+    $response = $this->httpClient->post($url, ['headers' => $headers, 'body' => $data]);
 
     $this->client->handleAuthResponse($response);
 
diff --git a/src/EntityNotFoundException.php b/src/EntityNotFoundException.php
index ea93beba..f10f447e 100644
--- a/src/EntityNotFoundException.php
+++ b/src/EntityNotFoundException.php
@@ -7,49 +7,78 @@ use Drupal\Component\Render\FormattableMarkup;
 use Throwable;
 
 /**
- * EntityNotFoundException extends Drupal\salesforce\Exception
+ * EntityNotFoundException extends Drupal\salesforce\Exception.
+ *
  * Thrown when a mapped entity cannot be loaded.
  */
 class EntityNotFoundException extends \RuntimeException {
 
   use StringTranslationTrait;
 
-  protected $entity_properties;
+  /**
+   * A list of entity properties, for logging.
+   *
+   * @var mixed
+   */
+  protected $entityProperties;
 
-  protected $entity_type_id;
+  /**
+   * Entity type id, for logging.
+   *
+   * @var string
+   */
+  protected $entityTypeId;
 
   /**
    * EntityNotFoundException constructor.
    *
-   * @param $entity_properties
-   * @param $entity_type_id
+   * @param mixed $entityProperties
+   *   Entity properties.
+   * @param string $entityTypeId
+   *   Entity type id.
    * @param \Throwable|null $previous
+   *   Previous exception.
    */
-  public function __construct($entity_properties, $entity_type_id, Throwable $previous = NULL) {
-    parent::__construct($this->t('Entity not found. type: %type properties: %props', ['%type' => $entity_type_id, '%props' => var_export($entity_properties, TRUE)]), 0, $previous);
-    $this->entity_properties = $entity_properties;
-    $this->entity_type_id = $entity_type_id;
+  public function __construct($entityProperties, $entityTypeId, Throwable $previous = NULL) {
+    parent::__construct($this->t('Entity not found. type: %type properties: %props', [
+        '%type' => $entityTypeId,
+        '%props' => var_export($entityProperties, TRUE)
+      ]), 0, $previous);
+    $this->entityProperties = $entityProperties;
+    $this->entityTypeId = $entityTypeId;
   }
 
   /**
+   * Getter.
+   *
    * @return mixed
+   *   The entityProperties.
    */
   public function getEntityProperties() {
-    return $this->entity_properties;
+    return $this->entityProperties;
   }
 
   /**
-   * @return mixed
+   * Getter.
+   *
+   * @return string
+   *   The entityTypeId.
    */
   public function getEntityTypeId() {
-    return $this->entity_type_id;
+    return $this->entityTypeId;
   }
 
   /**
+   * Get a formattable message.
+   *
    * @return \Drupal\Component\Render\FormattableMarkup
+   *   The message.
    */
   public function getFormattableMessage() {
-    return new FormattableMarkup('Entity not found. type: %type properties: %props', ['%type' => $this->entity_type_id, '%props' => var_export($this->entity_properties, TRUE)]);
+    return new FormattableMarkup('Entity not found. type: %type properties: %props', [
+        '%type' => $this->entityTypeId,
+        '%props' => var_export($this->entityProperties, TRUE)
+      ]);
   }
 
 }
diff --git a/src/Form/AuthorizeForm.php b/src/Form/AuthorizeForm.php
index 52b66693..e2dc275a 100644
--- a/src/Form/AuthorizeForm.php
+++ b/src/Form/AuthorizeForm.php
@@ -10,6 +10,7 @@ use Drupal\Core\Routing\TrustedRedirectResponse;
 use Drupal\Core\State\StateInterface;
 use Drupal\Core\Url;
 use Drupal\salesforce\Rest\RestClientInterface;
+use Drupal\salesforce_encrypt\Rest\EncryptedRestClientInterface;
 use GuzzleHttp\Exception\RequestException;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -26,7 +27,7 @@ class AuthorizeForm extends ConfigFormBase {
    *
    * @var \Drupal\salesforce\Rest\RestClientInterface
    */
-  protected $sf_client;
+  protected $client;
 
   /**
    * The sevent dispatcher service..
@@ -51,10 +52,12 @@ class AuthorizeForm extends ConfigFormBase {
    *   The factory for configuration objects.
    * @param \Drupal\Core\State\StateInterface $state
    *   The state keyvalue collection to use.
+   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
+   *   The event dispatcher.
    */
   public function __construct(ConfigFactoryInterface $config_factory, RestClientInterface $salesforce_client, StateInterface $state, EventDispatcherInterface $event_dispatcher) {
     parent::__construct($config_factory);
-    $this->sf_client = $salesforce_client;
+    $this->client = $salesforce_client;
     $this->state = $state;
     $this->eventDispatcher = $event_dispatcher;
   }
@@ -92,9 +95,11 @@ class AuthorizeForm extends ConfigFormBase {
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
     $config = $this->config('salesforce.settings');
-    $encrypted = is_subclass_of($this->sf_client, 'Drupal\salesforce_encrypt\Rest\EncryptedRestClientInterface');
+    $encrypted = is_subclass_of($this->client, EncryptedRestClientInterface::class);
     $url = new Url('salesforce.oauth_callback', [], ['absolute' => TRUE]);
-    drupal_set_message($this->t('Callback URL: :url', [':url' => str_replace('http:', 'https:', $url->toString())]));
+    drupal_set_message($this->t('Callback URL: :url', [
+        ':url' => str_replace('http:', 'https:', $url->toString())
+      ]));
 
     $form['creds'] = [
       '#title' => $this->t('API / OAuth Connection Settings'),
@@ -107,14 +112,14 @@ class AuthorizeForm extends ConfigFormBase {
       '#type' => 'textfield',
       '#description' => $this->t('Consumer key of the Salesforce remote application you want to grant access to'),
       '#required' => TRUE,
-      '#default_value' => $encrypted ? $this->sf_client->decrypt($config->get('consumer_key')) : $config->get('consumer_key'),
+      '#default_value' => $encrypted ? $this->client->decrypt($config->get('consumer_key')) : $config->get('consumer_key'),
     ];
     $form['creds']['consumer_secret'] = [
       '#title' => $this->t('Salesforce consumer secret'),
       '#type' => 'textfield',
       '#description' => $this->t('Consumer secret of the Salesforce remote application you want to grant access to'),
       '#required' => TRUE,
-      '#default_value' => $encrypted ? $this->sf_client->decrypt($config->get('consumer_secret')) : $config->get('consumer_secret'),
+      '#default_value' => $encrypted ? $this->client->decrypt($config->get('consumer_secret')) : $config->get('consumer_secret'),
     ];
     $form['creds']['login_url'] = [
       '#title' => $this->t('Login URL'),
@@ -126,11 +131,11 @@ class AuthorizeForm extends ConfigFormBase {
 
     // If fully configured, attempt to connect to Salesforce and return a list
     // of resources.
-    if ($this->sf_client->isAuthorized()) {
+    if ($this->client->isAuthorized()) {
       $form['creds']['#open'] = FALSE;
       $form['creds']['#description'] = $this->t('Your Salesforce salesforce instance is currently authorized. Enter credentials here only to change credentials.');
       try {
-        $resources = $this->sf_client->listResources();
+        $resources = $this->client->listResources();
         foreach ($resources->resources as $key => $path) {
           $items[] = $key . ': ' . $path;
         }
@@ -162,13 +167,14 @@ class AuthorizeForm extends ConfigFormBase {
    * Return whether or not the given URL is a valid endpoint.
    *
    * @return bool
+   *   True is the given url is valid.
    */
   public static function validEndpoint($url) {
     return UrlHelper::isValid($url, TRUE);
   }
 
   /**
-   *
+   * Validate handler for auth form. Basic sanity checking.
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
     if (!self::validEndpoint($form_state->getValue('login_url'))) {
@@ -186,16 +192,16 @@ class AuthorizeForm extends ConfigFormBase {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $values = $form_state->getValues();
-    $this->sf_client->setConsumerKey($values['consumer_key']);
-    $this->sf_client->setConsumerSecret($values['consumer_secret']);
-    $this->sf_client->setLoginUrl($values['login_url']);
+    $this->client->setConsumerKey($values['consumer_key']);
+    $this->client->setConsumerSecret($values['consumer_secret']);
+    $this->client->setLoginUrl($values['login_url']);
 
     try {
-      $path = $this->sf_client->getAuthEndpointUrl();
+      $path = $this->client->getAuthEndpointUrl();
       $query = [
-        'redirect_uri' => $this->sf_client->getAuthCallbackUrl(),
+        'redirect_uri' => $this->client->getAuthCallbackUrl(),
         'response_type' => 'code',
-        'client_id' => $this->sf_client->getConsumerKey(),
+        'client_id' => $this->client->getConsumerKey(),
       ];
 
       // Send the user along to the Salesforce OAuth login form. If successful,
diff --git a/src/Form/RevokeAuthorizationForm.php b/src/Form/RevokeAuthorizationForm.php
index 6789df37..16ada581 100644
--- a/src/Form/RevokeAuthorizationForm.php
+++ b/src/Form/RevokeAuthorizationForm.php
@@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 /**
- *
+ * Revoke the current oauth creds.
  */
 class RevokeAuthorizationForm extends ConfigFormBase {
 
@@ -22,7 +22,7 @@ class RevokeAuthorizationForm extends ConfigFormBase {
    *
    * @var \Drupal\salesforce\Rest\RestClientInterface
    */
-  protected $sf_client;
+  protected $client;
 
   /**
    * The sevent dispatcher service..
@@ -45,12 +45,12 @@ class RevokeAuthorizationForm extends ConfigFormBase {
    *   The factory for configuration objects.
    * @param \Drupal\salesforce\Rest\RestClientInterface $salesforce_client
    *   The factory for configuration objects.
-   * @param \Drupal\Core\State\StateInterface $state
-   *   The state keyvalue collection to use.
+   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
+   *   The event dispatcher.
    */
   public function __construct(ConfigFactoryInterface $config_factory, RestClientInterface $salesforce_client, EventDispatcherInterface $event_dispatcher) {
     parent::__construct($config_factory);
-    $this->sf_client = $salesforce_client;
+    $this->client = $salesforce_client;
     $this->eventDispatcher = $event_dispatcher;
   }
 
@@ -85,7 +85,7 @@ class RevokeAuthorizationForm extends ConfigFormBase {
    * {@inheritdoc}
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
-    if (!$this->sf_client->isAuthorized()) {
+    if (!$this->client->isAuthorized()) {
       drupal_set_message($this->t('Drupal is not authenticated to Salesforce.'), 'warning');
       return;
     }
@@ -106,10 +106,10 @@ class RevokeAuthorizationForm extends ConfigFormBase {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    $this->sf_client->setAccessToken('');
-    $this->sf_client->setRefreshToken('');
-    $this->sf_client->setInstanceUrl('');
-    $this->sf_client->setIdentity(FALSE);
+    $this->client->setAccessToken('');
+    $this->client->setRefreshToken('');
+    $this->client->setInstanceUrl('');
+    $this->client->setIdentity(FALSE);
     drupal_set_message($this->t('Salesforce OAuth tokens have been revoked.'));
     $this->eventDispatcher->dispatch(SalesforceEvents::NOTICE, new SalesforceNoticeEvent(NULL, "Salesforce OAuth tokens revoked."));
   }
diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php
index dad26cd6..1dd19ddc 100644
--- a/src/Form/SettingsForm.php
+++ b/src/Form/SettingsForm.php
@@ -20,7 +20,7 @@ class SettingsForm extends ConfigFormBase {
    *
    * @var \Drupal\salesforce\Rest\RestClientInterface
    */
-  protected $sf_client;
+  protected $client;
 
   /**
    * The sevent dispatcher service..
@@ -36,10 +36,12 @@ class SettingsForm extends ConfigFormBase {
    *   The factory for configuration objects.
    * @param \Drupal\salesforce\Rest\RestClientInterface $salesforce_client
    *   The factory for configuration objects.
+   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
+   *   The event dispatcher.
    */
   public function __construct(ConfigFactoryInterface $config_factory, RestClientInterface $salesforce_client, EventDispatcherInterface $event_dispatcher) {
     parent::__construct($config_factory);
-    $this->sf_client = $salesforce_client;
+    $this->client = $salesforce_client;
     $this->eventDispatcher = $event_dispatcher;
   }
 
@@ -193,7 +195,7 @@ class SettingsForm extends ConfigFormBase {
     $use_latest = $form_state->getValue('use_latest');
     $config->set('use_latest', $use_latest);
     if (!$use_latest) {
-      $versions = $this->sf_client->getVersions();
+      $versions = $this->client->getVersions();
       $version = $versions[$form_state->getValue('rest_api_version')];
       $config->set('rest_api_version', $version);
     }
@@ -205,9 +207,10 @@ class SettingsForm extends ConfigFormBase {
    * Helper method to generate Salesforce option list for select element.
    *
    * @return array
+   *   The version options.
    */
   protected function getVersionOptions() {
-    $versions = $this->sf_client->getVersions();
+    $versions = $this->client->getVersions();
     array_walk($versions,
       function (&$item, $key) {
         $item = $item['label'];
diff --git a/src/Rest/RestClient.php b/src/Rest/RestClient.php
index d552e9ef..5aede0ab 100644
--- a/src/Rest/RestClient.php
+++ b/src/Rest/RestClient.php
@@ -106,6 +106,8 @@ class RestClient implements RestClientInterface {
    *   The cache service.
    * @param \Drupal\Component\Serialization\Json $json
    *   The JSON serializer service.
+   * @param \Drupal\Component\Datetime\TimeInterface $time
+   *   The Time service.
    */
   public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, StateInterface $state, CacheBackendInterface $cache, Json $json, TimeInterface $time) {
     $this->configFactory = $config_factory;
@@ -189,7 +191,6 @@ class RestClient implements RestClientInterface {
    *
    * @param string $url
    *   Fully-qualified URL to resource.
-   *
    * @param array $params
    *   Parameters to provide.
    * @param string $method
@@ -590,10 +591,10 @@ class RestClient implements RestClientInterface {
   }
 
   /**
-   * Helper method to extract API Usage info from response header and write to
-   * stateful variable.
+   * Helper to extract API Usage info from response header and write to state.
    *
-   * @param RestResponse $response
+   * @param \Drupal\salesforce\Rest\RestResponse $response
+   *   A REST API response.
    */
   protected function updateApiUsage(RestResponse $response) {
     if ($limit_info = $response->getHeader('Sforce-Limit-Info')) {
@@ -685,7 +686,7 @@ class RestClient implements RestClientInterface {
       return $cache->data;
     }
     else {
-      $response = new RestResponse_Describe($this->apiCall("sobjects/{$name}/describe", [], 'GET', TRUE));
+      $response = new RestResponseDescribe($this->apiCall("sobjects/{$name}/describe", [], 'GET', TRUE));
       $this->cache->set('salesforce:object:' . $name, $response, $this->getRequestTime() + self::CACHE_LIFETIME, ['salesforce']);
       return $response;
     }
@@ -767,14 +768,10 @@ class RestClient implements RestClientInterface {
   }
 
   /**
-   * Return a list of available resources for the configured API version.
-   *
-   * @return \Drupal\salesforce\Rest\RestResponse_Resources
-   *
-   * @addtogroup salesforce_apicalls
+   * {@inheritdoc}
    */
   public function listResources() {
-    return new RestResponse_Resources($this->apiCall('', [], 'GET', TRUE));
+    return new RestResponseResources($this->apiCall('', [], 'GET', TRUE));
   }
 
   /**
diff --git a/src/Rest/RestClientInterface.php b/src/Rest/RestClientInterface.php
index 6426c449..8c64592a 100644
--- a/src/Rest/RestClientInterface.php
+++ b/src/Rest/RestClientInterface.php
@@ -395,7 +395,7 @@ interface RestClientInterface {
    * @param bool $reset
    *   Whether to reset the cache and retrieve a fresh version from Salesforce.
    *
-   * @return \Drupal\salesforce\Rest\RestResponse_Describe
+   * @return \Drupal\salesforce\Rest\RestResponseDescribe
    *   The describe result.
    *
    * @addtogroup salesforce_apicalls
@@ -529,7 +529,7 @@ interface RestClientInterface {
   /**
    * Return a list of available resources for the configured API version.
    *
-   * @return \Drupal\salesforce\Rest\RestResponse_Resources
+   * @return \Drupal\salesforce\Rest\RestResponseResources
    *   The response.
    *
    * @addtogroup salesforce_apicalls
diff --git a/src/Rest/RestException.php b/src/Rest/RestException.php
index 20f04edc..1cf71e2f 100644
--- a/src/Rest/RestException.php
+++ b/src/Rest/RestException.php
@@ -12,15 +12,31 @@ use Psr\Http\Message\ResponseInterface;
  */
 class RestException extends \RuntimeException implements ExceptionInterface {
 
+  /**
+   * The current Response.
+   *
+   * @var \Psr\Http\Message\ResponseInterface|null
+   */
   protected $response;
 
+  /**
+   * The response body.
+   *
+   * @var string
+   */
+  protected $body;
+
   /**
    * RestException constructor.
    *
    * @param \Psr\Http\Message\ResponseInterface|null $response
+   *   A response, if available.
    * @param string $message
+   *   Message (optional).
    * @param int $code
+   *   Erorr code (optional).
    * @param \Exception|null $previous
+   *   Previous exception (optional).
    */
   public function __construct(ResponseInterface $response = NULL, $message = "", $code = 0, \Exception $previous = NULL) {
     $this->response = $response;
@@ -29,22 +45,32 @@ class RestException extends \RuntimeException implements ExceptionInterface {
   }
 
   /**
+   * Getter.
+   *
    * @return null|\Psr\Http\Message\ResponseInterface
+   *   The response.
    */
   public function getResponse() {
     return $this->response;
   }
 
   /**
+   * Getter.
+   *
    * @return string|null
+   *   The response body.
    */
   public function getResponseBody() {
+    if ($this->body) {
+      return $this->body;
+    }
     if (!$this->response) {
       return NULL;
     }
     $body = $this->response->getBody();
     if ($body) {
-      return $body->getContents();
+      $this->body = $body->getContents();
+      return $this->body;
     }
     return '';
   }
diff --git a/src/Rest/RestResponse.php b/src/Rest/RestResponse.php
index 74a1c990..298ef578 100644
--- a/src/Rest/RestResponse.php
+++ b/src/Rest/RestResponse.php
@@ -29,9 +29,10 @@ class RestResponse extends Response {
   protected $data;
 
   /**
-   * {@inheritdoc}
+   * RestResponse constructor.
    *
-   * @throws \Drupal\salesforce\Rest\RestException if body cannot be json-decoded
+   * @param \GuzzleHttp\Psr7\Response $response
+   *   A response.
    */
   public function __construct(Response $response) {
     $this->response = $response;
@@ -43,10 +44,13 @@ class RestResponse extends Response {
    * Magic getter method to return the given property.
    *
    * @param string $key
+   *   The property name.
    *
    * @return mixed
+   *   The property value.
    *
-   * @throws \Exception if $key is not a property
+   * @throws \Exception
+   *   If $key property does not exist.
    */
   public function __get($key) {
     if (!property_exists($this, $key)) {
diff --git a/src/Rest/RestResponseDescribe.php b/src/Rest/RestResponseDescribe.php
new file mode 100644
index 00000000..7d9b77a8
--- /dev/null
+++ b/src/Rest/RestResponseDescribe.php
@@ -0,0 +1,167 @@
+<?php
+
+namespace Drupal\salesforce\Rest;
+
+/**
+ * Class RestResponseDescribe.
+ *
+ * @package Drupal\salesforce\Rest
+ */
+class RestResponseDescribe extends RestResponse {
+
+  /**
+   * Array of field definitions for this SObject type, indexed by machine name.
+   *
+   * @var array
+   */
+  protected $fields;
+
+  /**
+   * The name of this SObject type, e.g. "Contact", "Account", "Opportunity".
+   *
+   * @var string
+   */
+  protected $name;
+
+  /**
+   * Flattened fields mapping field name => field label.
+   *
+   * @var array
+   */
+  private $fieldOptions;
+
+  /**
+   * See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_describe.htm.
+   *
+   * @param \Drupal\salesforce\Rest\RestResponse $response
+   *   The Response.
+   */
+  public function __construct(RestResponse $response) {
+    parent::__construct($response->response);
+
+    $this->name = $response->data['name'];
+    $this->fields = [];
+    // Index fields by machine name, so we don't have to search every time.
+    foreach ($response->data['fields'] as $field) {
+      $this->fields[$field['name']] = $field;
+    }
+
+    foreach ($response->data as $key => $value) {
+      if ($key == 'fields') {
+        continue;
+      }
+      $this->$key = $value;
+    }
+    $this->data = $response->data;
+  }
+
+  /**
+   * Getter for name.
+   *
+   * @return string
+   *   The object name.
+   */
+  public function getName() {
+    return $this->name;
+  }
+
+  /**
+   * Getter.
+   *
+   * @return array
+   *   The fields.
+   */
+  public function getFields() {
+    return $this->fields;
+  }
+
+  /**
+   * Return a field definition for the given field name.
+   *
+   * A single Salesforce field may contain the following keys:
+   *    aggregatable
+   *    autoNumber
+   *    byteLength
+   *    calculated
+   *    calculatedFormula
+   *    cascadeDelete
+   *    caseSensitive
+   *    controllerName
+   *    createable
+   *    custom
+   *    defaultValue
+   *    defaultValueFormula
+   *    defaultedOnCreate
+   *    dependentPicklist
+   *    deprecatedAndHidden
+   *    digits
+   *    displayLocationInDecimal
+   *    encrypted
+   *    externalId
+   *    extraTypeInfo
+   *    filterable
+   *    filteredLookupInfo
+   *    groupable
+   *    highScaleNumber
+   *    htmlFormatted
+   *    idLookup
+   *    inlineHelpText
+   *    label
+   *    length
+   *    mask
+   *    maskType
+   *    name
+   *    nameField
+   *    namePointing
+   *    nillable
+   *    permissionable
+   *    picklistValues
+   *    precision
+   *    queryByDistance
+   *    referenceTargetField
+   *    referenceTo
+   *    relationshipName
+   *    relationshipOrder
+   *    restrictedDelete
+   *    restrictedPicklist
+   *    scale
+   *    soapType
+   *    sortable
+   *    type
+   *    unique
+   *    updateable
+   *    writeRequiresMasterRead.
+   *
+   * For more information @see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fields_describe.htm.
+   *
+   * @param string $field_name
+   *   A field name.
+   *
+   * @return array
+   *   The field definition.
+   *
+   * @throws \Exception
+   *   If field_name is not defined for this SObject type.
+   */
+  public function getField($field_name) {
+    if (empty($this->fields[$field_name])) {
+      throw new \Exception("No field $field_name");
+    }
+    return $this->fields[$field_name];
+  }
+
+  /**
+   * Return a one-dimensional array of field names => field labels.
+   *
+   * @return array
+   *   The field options.
+   */
+  public function getFieldOptions() {
+    if (!isset($this->fieldOptions)) {
+      $this->fieldOptions = array_column($this->fields, 'label', 'name');
+      asort($this->fieldOptions);
+    }
+    return $this->fieldOptions;
+  }
+
+}
diff --git a/src/Rest/RestResponseResources.php b/src/Rest/RestResponseResources.php
new file mode 100644
index 00000000..4cd3d276
--- /dev/null
+++ b/src/Rest/RestResponseResources.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\salesforce\Rest;
+
+/**
+ * Class RestResponseResources.
+ *
+ * @package Drupal\salesforce\Rest
+ */
+class RestResponseResources extends RestResponse {
+
+  /**
+   * List of API endpoint paths.
+   *
+   * Accessible via RestResponse:__get()
+   *
+   * @var array
+   */
+  protected $resources;
+
+  /**
+   * RestResponseResources constructor.
+   *
+   * See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_discoveryresource.htm.
+   *
+   * @param \Drupal\salesforce\Rest\RestResponse $response
+   *   The response.
+   */
+  public function __construct(RestResponse $response) {
+    parent::__construct($response->response);
+    foreach ($response->data as $key => $path) {
+      $this->resources[$key] = $path;
+    }
+  }
+
+}
diff --git a/src/Rest/RestResponse_Describe.php b/src/Rest/RestResponse_Describe.php
index 3ce0a664..00dcff44 100644
--- a/src/Rest/RestResponse_Describe.php
+++ b/src/Rest/RestResponse_Describe.php
@@ -3,155 +3,10 @@
 namespace Drupal\salesforce\Rest;
 
 /**
- * Class RestResponse_Describe.
+ * Use RestResponseDescribe.
  *
- * @package Drupal\salesforce\Rest
+ * @deprecated Will be removed in 8.x-3.3
  */
-class RestResponse_Describe extends RestResponse {
-
-  /**
-   * Array of field definitions for this SObject type, indexed by machine name.
-   *
-   * @var array
-   */
-  protected $fields;
-
-  /**
-   * The name of this SObject type, e.g. "Contact", "Account", "Opportunity".
-   *
-   * @var string
-   */
-  protected $name;
-
-  /**
-   * Flattened fields mapping field name => field label.
-   *
-   * @var array
-   */
-  private $field_options;
-
-  /**
-   * See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_describe.htm.
-   *
-   * @param \Drupal\salesforce\Rest\RestResponse $response
-   */
-  public function __construct(RestResponse $response) {
-    parent::__construct($response->response);
-
-    $this->name = $response->data['name'];
-    $this->fields = [];
-    // Index fields by machine name, so we don't have to search every time.
-    foreach ($response->data['fields'] as $field) {
-      $this->fields[$field['name']] = $field;
-    }
-
-    foreach ($response->data as $key => $value) {
-      if ($key == 'fields') {
-        continue;
-      }
-      $this->$key = $value;
-    }
-    $this->data = $response->data;
-  }
-
-  /**
-   * @return string
-   */
-  public function getName() {
-    return $this->name;
-  }
-
-  /**
-   * Getter.
-   *
-   * @return array
-   */
-  public function getFields() {
-    return $this->fields;
-  }
-
-  /**
-   * Return a field definition for the given field name.
-   * A single Salesforce field may contain the following keys:
-   *    aggregatable
-   *    autoNumber
-   *    byteLength
-   *    calculated
-   *    calculatedFormula
-   *    cascadeDelete
-   *    caseSensitive
-   *    controllerName
-   *    createable
-   *    custom
-   *    defaultValue
-   *    defaultValueFormula
-   *    defaultedOnCreate
-   *    dependentPicklist
-   *    deprecatedAndHidden
-   *    digits
-   *    displayLocationInDecimal
-   *    encrypted
-   *    externalId
-   *    extraTypeInfo
-   *    filterable
-   *    filteredLookupInfo
-   *    groupable
-   *    highScaleNumber
-   *    htmlFormatted
-   *    idLookup
-   *    inlineHelpText
-   *    label
-   *    length
-   *    mask
-   *    maskType
-   *    name
-   *    nameField
-   *    namePointing
-   *    nillable
-   *    permissionable
-   *    picklistValues
-   *    precision
-   *    queryByDistance
-   *    referenceTargetField
-   *    referenceTo
-   *    relationshipName
-   *    relationshipOrder
-   *    restrictedDelete
-   *    restrictedPicklist
-   *    scale
-   *    soapType
-   *    sortable
-   *    type
-   *    unique
-   *    updateable
-   *    writeRequiresMasterRead.
-   *
-   * For more information @see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fields_describe.htm.
-   *
-   * @param string $field_name
-   *
-   * @return array field definition
-   *
-   * @throws \Exception if field_name is not defined for this SObject type
-   */
-  public function getField($field_name) {
-    if (empty($this->fields[$field_name])) {
-      throw new \Exception("No field $field_name");
-    }
-    return $this->fields[$field_name];
-  }
-
-  /**
-   * Return a one-dimensional array of field names => field labels.
-   *
-   * @return array
-   */
-  public function getFieldOptions() {
-    if (!isset($this->field_options)) {
-      $this->field_options = array_column($this->fields, 'label', 'name');
-      asort($this->field_options);
-    }
-    return $this->field_options;
-  }
+class RestResponse_Describe extends RestResponseDescribe {
 
 }
diff --git a/src/Rest/RestResponse_Resources.php b/src/Rest/RestResponse_Resources.php
index eee4985e..5290dca6 100644
--- a/src/Rest/RestResponse_Resources.php
+++ b/src/Rest/RestResponse_Resources.php
@@ -3,33 +3,10 @@
 namespace Drupal\salesforce\Rest;
 
 /**
- * Class RestResponse_Resources.
+ * Use RestResponseResources.
  *
- * @package Drupal\salesforce\Rest
+ * @deprecated Will be removed in 8.x-3.3
  */
-class RestResponse_Resources extends RestResponse {
-
-  /**
-   * List of API endpoint paths.
-   *
-   * Accessible via RestResponse:__get()
-   *
-   * @var array
-   */
-  protected $resources;
-
-  /**
-   * RestResponse_Resources constructor.
-   *
-   * See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_discoveryresource.htm.
-   *
-   * @param \Drupal\salesforce\Rest\RestResponse $response
-   */
-  public function __construct(RestResponse $response) {
-    parent::__construct($response->response);
-    foreach ($response->data as $key => $path) {
-      $this->resources[$key] = $path;
-    }
-  }
+class RestResponse_Resources extends RestResponseResources {
 
 }
diff --git a/src/SFID.php b/src/SFID.php
index aed1df46..6ddd8724 100644
--- a/src/SFID.php
+++ b/src/SFID.php
@@ -15,7 +15,8 @@ class SFID {
   /**
    * SFID constructor.
    *
-   * @param $id
+   * @param string $id
+   *   The SFID.
    *
    * @throws \Exception
    */
@@ -30,7 +31,10 @@ class SFID {
   }
 
   /**
+   * Magic method wrapping the SFID string.
+   *
    * @return string
+   *   The SFID.
    */
   public function __toString() {
     return (string) $this->id;
diff --git a/src/SObject.php b/src/SObject.php
index c48e81f8..7067675b 100644
--- a/src/SObject.php
+++ b/src/SObject.php
@@ -16,6 +16,7 @@ class SObject {
    * SObject constructor.
    *
    * @param array $data
+   *   The SObject field data.
    *
    * @throws \Exception
    */
@@ -45,21 +46,30 @@ class SObject {
   }
 
   /**
+   * SFID Getter.
+   *
    * @return \Drupal\salesforce\SFID
+   *   The record id.
    */
   public function id() {
     return $this->id;
   }
 
   /**
-   * @return mixed
+   * Type getter.
+   *
+   * @return string
+   *   The object type.
    */
   public function type() {
     return $this->type;
   }
 
   /**
+   * Fields getter.
    *
+   * @return array
+   *   All SObject fields.
    */
   public function fields() {
     return $this->fields;
@@ -69,8 +79,10 @@ class SObject {
    * Given $key, return corresponding field value.
    *
    * @return mixed
+   *   The value.
    *
-   * @throws \Exception if $key is not found
+   * @throws \Exception
+   *   If $key is not found.
    */
   public function field($key) {
     if (!array_key_exists($key, $this->fields)) {
diff --git a/src/SelectQueryInterface.php b/src/SelectQueryInterface.php
index 329a54f5..c971b421 100644
--- a/src/SelectQueryInterface.php
+++ b/src/SelectQueryInterface.php
@@ -3,7 +3,7 @@
 namespace Drupal\salesforce;
 
 /**
- *
+ * A SOQL query interface.
  */
 interface SelectQueryInterface {
 
diff --git a/src/SelectQueryRaw.php b/src/SelectQueryRaw.php
index b8440cdf..55f67d32 100644
--- a/src/SelectQueryRaw.php
+++ b/src/SelectQueryRaw.php
@@ -3,7 +3,7 @@
 namespace Drupal\salesforce;
 
 /**
- *
+ * Allows for creating a select query by providing the SOQL string directly.
  */
 class SelectQueryRaw implements SelectQueryInterface {
 
diff --git a/src/SelectQueryResult.php b/src/SelectQueryResult.php
index 6aa867d5..18cf16f0 100644
--- a/src/SelectQueryResult.php
+++ b/src/SelectQueryResult.php
@@ -18,6 +18,7 @@ class SelectQueryResult {
    * SelectQueryResult constructor.
    *
    * @param array $results
+   *   The query results.
    */
   public function __construct(array $results) {
     $this->totalSize = $results['totalSize'];
@@ -32,38 +33,56 @@ class SelectQueryResult {
   }
 
   /**
-   * @return mixed
+   * Getter.
+   *
+   * @return string|null
+   *   The next record url, or null.
    */
   public function nextRecordsUrl() {
     return $this->nextRecordsUrl;
   }
 
   /**
-   * @return mixed
+   * Getter.
+   *
+   * @return int
+   *   The query size. For a single-page query, will be equal to total.
    */
   public function size() {
     return $this->totalSize;
   }
 
   /**
-   * @return mixed
+   * Indicates whether the query is "done", or has more results to be fetched.
+   *
+   * @return bool
+   *   Return FALSE if the query has more pages of results.
    */
   public function done() {
     return $this->done;
   }
 
   /**
+   * The results.
+   *
    * @return \Drupal\salesforce\SObject[]
+   *   The result records.
    */
   public function records() {
     return $this->records;
   }
 
   /**
+   * Fetch a particular record given its SFID.
+   *
    * @param \Drupal\salesforce\SFID $id
+   *   The SFID.
+   *
+   * @return \Drupal\salesforce\SObject
+   *   The record.
    *
-   * @return mixed
    * @throws \Exception
+   *   If the given SFID doesn't exist in these results.
    */
   public function record(SFID $id) {
     if (!isset($this->records[(string) $id])) {
diff --git a/src/Tests/SalesforceAdminSettingsTest.php b/src/Tests/SalesforceAdminSettingsTest.php
index f07ec680..8bb76de5 100644
--- a/src/Tests/SalesforceAdminSettingsTest.php
+++ b/src/Tests/SalesforceAdminSettingsTest.php
@@ -78,7 +78,7 @@ class SalesforceAdminSettingsTest extends WebTestBase {
   }
 
   /**
-   *
+   * Test that the oauth mechanism appropriately sends a redirect header.
    */
   public function testOauthCallback() {
     $this->drupalLogin($this->adminSalesforceUser);
diff --git a/src/Tests/TestHttpClient.php b/src/Tests/TestHttpClient.php
index af015ba5..fe2de237 100644
--- a/src/Tests/TestHttpClient.php
+++ b/src/Tests/TestHttpClient.php
@@ -6,6 +6,8 @@ use GuzzleHttp\Client;
 use GuzzleHttp\Psr7\Response;
 
 /**
+ * Empty http client.
+ *
  * @see tests/modules/salesforce_test_rest_client
  */
 class TestHttpClient extends Client {
diff --git a/src/Tests/TestRestClient.php b/src/Tests/TestRestClient.php
index 154400815123afe9f779fdca48d78534993b1fc2..0f1f6eb1e52bdca5c6a4514dc882ca7d739bc93c 100644
GIT binary patch
delta 32
mcmbQWjc?{Qz74ne8I333;a6>D5@=@<U<6{O?Mwp965Rm3CkbW%

delta 42
xcmbQajc?XAz74ne8BL}aPGc6C{DEI^y1`^d&Sp-5c1{6CAZFUmDZnhy4FE(t43q!>

diff --git a/tests/src/Unit/RestClientTest.php b/tests/src/Unit/RestClientTest.php
index 33c6578e..2935f526 100644
--- a/tests/src/Unit/RestClientTest.php
+++ b/tests/src/Unit/RestClientTest.php
@@ -6,8 +6,8 @@ use Drupal\Component\Serialization\Json;
 use Drupal\Tests\UnitTestCase;
 use Drupal\salesforce\Rest\RestClient;
 use Drupal\salesforce\Rest\RestResponse;
-use Drupal\salesforce\Rest\RestResponse_Describe;
-use Drupal\salesforce\Rest\RestResponse_Resources;
+use Drupal\salesforce\Rest\RestResponseDescribe;
+use Drupal\salesforce\Rest\RestResponseResources;
 use Drupal\salesforce\SFID;
 use Drupal\salesforce\SObject;
 use Drupal\salesforce\SelectQueryResult;
@@ -259,7 +259,7 @@ class RestClientTest extends UnitTestCase {
 
     // Test that we hit "apiCall" and get expected result:
     $result = $this->client->objectDescribe($name);
-    $expected = new RestResponse_Describe($restResponse);
+    $expected = new RestResponseDescribe($restResponse);
     $this->assertEquals($expected, $result);
 
     // Test that cache gets set correctly:
@@ -436,7 +436,7 @@ class RestClientTest extends UnitTestCase {
     $this->client->expects($this->once())
       ->method('apiCall')
       ->willReturn($restResponse);
-    $this->assertEquals(new RestResponse_Resources($restResponse), $this->client->listResources());
+    $this->assertEquals(new RestResponseResources($restResponse), $this->client->listResources());
   }
 
   /**
-- 
GitLab