Commit 52685c53 authored by Nathaniel Hoag's avatar Nathaniel Hoag Committed by Aaron Bauman
Browse files

Issue #2959145 by nhoag: Partial code comment and annotation cleanup

parent ebcb42c0
Loading
Loading
Loading
Loading
+8 −3
Changes for src/EntityNotFoundException.php: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\salesforce;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Component\Render\FormattableMarkup;
use Throwable;

/**
 * EntityNotFoundException extends Drupal\salesforce\Exception
@@ -18,7 +19,11 @@ class EntityNotFoundException extends \RuntimeException {
  protected $entity_type_id;

  /**
   * EntityNotFoundException constructor.
   *
   * @param $entity_properties
   * @param $entity_type_id
   * @param Throwable|NULL $previous
   */
  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);
@@ -27,21 +32,21 @@ class EntityNotFoundException extends \RuntimeException {
  }

  /**
   *
   * @return mixed
   */
  public function getEntityProperties() {
    return $this->entity_properties;
  }

  /**
   *
   * @return mixed
   */
  public function getEntityTypeId() {
    return $this->entity_type_id;
  }

  /**
   *
   * @return \Drupal\Component\Render\FormattableMarkup
   */
  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)]);
+2 −0
Changes for src/Exception.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ namespace Drupal\salesforce;
use Symfony\Component\Serializer\Exception\ExceptionInterface;

/**
 * Class Exception.
 *
 * @package Drupal\salesforce
 */
class Exception extends \RuntimeException implements ExceptionInterface {

+48 −20
Changes for src/Rest/RestClient.php: 48 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ use Drupal\Component\Datetime\TimeInterface;
class RestClient implements RestClientInterface {

  /**
   * Reponse object.
   * Response object.
   *
   * @var \GuzzleHttp\Psr7\Response
   */
@@ -48,7 +48,7 @@ class RestClient implements RestClientInterface {
  /**
   * Salesforce API URL.
   *
   * @var Drupal\Core\Url
   * @var \Drupal\Core\Url
   */
  protected $url;

@@ -69,7 +69,7 @@ class RestClient implements RestClientInterface {
  /**
   * The cache service.
   *
   * @var Drupal\Core\Cache\CacheBackendInterface
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $cache;

@@ -186,8 +186,11 @@ class RestClient implements RestClientInterface {
   * @param string $method
   *   Method to initiate the call, such as GET or POST.  Defaults to GET.
   *
   * @return GuzzleHttp\Psr7\Response
   * @return \GuzzleHttp\Psr7\Response
   *   Response object.
   *
   * @throws \Exception
   * @throws \GuzzleHttp\Exception\RequestException
   */
  protected function apiHttpRequest($url, array $params, $method) {
    if (!$this->getAccessToken()) {
@@ -211,6 +214,7 @@ class RestClient implements RestClientInterface {
   *
   * @param string $url
   * @return mixed
   * @throws \Exception
   */
  public function httpRequestRaw($url) {
    if (!$this->getAccessToken()) {
@@ -236,11 +240,11 @@ class RestClient implements RestClientInterface {
   * @param string $method
   *   Method to initiate the call, such as GET or POST.  Defaults to GET.
   *
   * @throws RequestException
   *   Request exception.
   *
   * @return GuzzleHttp\Psr7\Response
   * @return \GuzzleHttp\Psr7\Response
   *   Response object.
   *
   * @throws \GuzzleHttp\Exception\RequestException
   *   Request exception.
   */
  protected function httpRequest($url, $data = NULL, array $headers = [], $method = 'GET') {
    // Build the request, including path and headers. Internal use.
@@ -344,6 +348,9 @@ class RestClient implements RestClientInterface {
   *
   * @param bool $use_latest
   * @param int $version
   *
   * @throws \Exception
   * @throws \GuzzleHttp\Exception\RequestException
   */
  public function setApiVersion($use_latest = TRUE, $version = NULL) {
    if ($use_latest) {
@@ -352,7 +359,7 @@ class RestClient implements RestClientInterface {
    else {
      $versions = $this->getVersions();
      if (empty($versions[$version])) {
        throw new Exception("Version $version is not available.");
        throw new \Exception("Version $version is not available.");
      }
      $version = $versions[$version];
      $this->config->set('rest_api_version', $version);
@@ -415,6 +422,8 @@ class RestClient implements RestClientInterface {
   *
   * @param string $url
   *   URL to set.
   *
   * @return $this
   */
  public function setInstanceUrl($url) {
    $this->state->set('salesforce.instance_url', $url);
@@ -434,6 +443,8 @@ class RestClient implements RestClientInterface {
   *
   * @param string $token
   *   Access token from Salesforce.
   *
   * @return $this
   */
  public function setAccessToken($token) {
    $this->state->set('salesforce.access_token', $token);
@@ -452,6 +463,8 @@ class RestClient implements RestClientInterface {
   *
   * @param string $token
   *   Refresh token from Salesforce.
   *
   * @return $this
   */
  public function setRefreshToken($token) {
    $this->state->set('salesforce.refresh_token', $token);
@@ -488,9 +501,13 @@ class RestClient implements RestClientInterface {
  /**
   * Helper callback for OAuth handshake, and refreshToken()
   *
   * @param GuzzleHttp\Psr7\Response $response
   * @param \GuzzleHttp\Psr7\Response $response
   *   Response object from refreshToken or authToken endpoints.
   *
   * @return $this
   *
   * @throws \Exception
   *
   * @see SalesforceController::oauthCallback()
   * @see self::refreshToken()
   */
@@ -519,7 +536,10 @@ class RestClient implements RestClientInterface {
   * @param string $id
   *   Identity URL.
   *
   * @throws Exception
   * @return $this
   *
   * @throws \Exception
   * @throws \GuzzleHttp\Exception\RequestException
   */
  public function initializeIdentity($id) {
    $headers = [
@@ -563,7 +583,7 @@ class RestClient implements RestClientInterface {
   * @return string
   *   Redirect URL.
   *
   * @see Drupal\salesforce\Controller\SalesforceController
   * @see \Drupal\salesforce\Controller\SalesforceController
   */
  public function getAuthCallbackUrl() {
    return Url::fromRoute('salesforce.oauth_callback', [], [
@@ -595,12 +615,14 @@ class RestClient implements RestClientInterface {
  /**
   * Wrapper for "Versions" resource to list information about API releases.
   *
   * @param $reset
   * @param bool $reset
   *   Whether to reset cache.
   *
   * @return array
   *   Array of all available Salesforce versions, or empty array if version
   *   info is not available.
   *
   * @throws \GuzzleHttp\Exception\RequestException
   */
  public function getVersions($reset = FALSE) {
    if (!$reset && ($cache = $this->cache->get('salesforce:versions'))) {
@@ -726,9 +748,11 @@ class RestClient implements RestClientInterface {
   * @param bool $reset
   *   Whether to reset the cache and retrieve a fresh version from Salesforce.
   *
   * @return RestResponse_Describe
   * @return \Drupal\salesforce\Rest\RestResponse_Describe
   *   Salesforce object description object.
   *
   * @throws \Exception
   *
   * @addtogroup salesforce_apicalls
   */
  public function objectDescribe($name, $reset = FALSE) {
@@ -754,7 +778,7 @@ class RestClient implements RestClientInterface {
   * @param array $params
   *   Values of the fields to set for the object.
   *
   * @return Drupal\salesforce\SFID
   * @return \Drupal\salesforce\SFID
   *   Salesforce ID object.
   *
   * @addtogroup salesforce_apicalls
@@ -781,8 +805,7 @@ class RestClient implements RestClientInterface {
   * @param array $params
   *   Values of the fields to set for the object.
   *
   * @return mixed
   *   Drupal\salesforce\SFID or NULL.
   * @return \Drupal\salesforce\SFID|null
   *
   * @addtogroup salesforce_apicalls
   */
@@ -876,6 +899,8 @@ class RestClient implements RestClientInterface {
   *   (optional) If TRUE, 404 response code will cause RequestException to be
   *   thrown. Otherwise, hide those errors. Default is FALSE.
   *
   * @throws \Exception
   *
   * @addtogroup salesforce_apicalls
   */
  public function objectDelete($name, $id, $throw_exception = FALSE) {
@@ -909,7 +934,7 @@ class RestClient implements RestClientInterface {
  /**
   * Return a list of available resources for the configured API version.
   *
   * @return Drupal\salesforce\Rest\RestResponse_Resources
   * @return \Drupal\salesforce\Rest\RestResponse_Resources
   *
   * @addtogroup salesforce_apicalls
   */
@@ -965,6 +990,8 @@ class RestClient implements RestClientInterface {
   * @return array
   *   If $name is given, an array of record types indexed by developer name.
   *   Otherwise, an array of record type arrays, indexed by object type name.
   *
   * @throws \Exception
   */
  public function getRecordTypes($name = NULL, $reset = FALSE) {
    if (!$reset && ($cache = $this->cache->get('salesforce:record_types'))) {
@@ -999,11 +1026,12 @@ class RestClient implements RestClientInterface {
   *   Object type name, E.g., Contact, Account.
   * @param string $devname
   *   RecordType DeveloperName, e.g. Donation, Membership, etc.
   * @param bool $reset
   *
   * @return \Drupal\salesforce\SFID
   *   The Salesforce ID of the given Record Type, or null.
   *
   * @throws Exception if record type not found
   * @throws \Exception if record type not found
   */
  public function getRecordTypeIdByDeveloperName($name, $devname, $reset = FALSE) {
    $record_types = $this->getRecordTypes();
@@ -1022,7 +1050,7 @@ class RestClient implements RestClientInterface {
   * @return string
   *   Object type's name.
   *
   * @throws Exception
   * @throws \Exception
   *   If SFID doesn't match any object type.
   */
  public function getObjectTypeName(SFID $id) {
+15 −18
Changes for src/Rest/RestClientInterface.php: 15 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -42,9 +42,9 @@ interface RestClientInterface {
   *   Defaults to FALSE for backwards compatibility.
   *
   * @return mixed
   *   Reponce object or response data.
   *   Response object or response data.
   *
   * @throws GuzzleHttp\Exception\RequestException
   * @throws \GuzzleHttp\Exception\RequestException
   */
  public function apiCall($path, array $params = [], $method = 'GET', $returnObject = FALSE);

@@ -171,14 +171,14 @@ interface RestClientInterface {
  /**
   * Refresh access token based on the refresh token.
   *
   * @throws Exception
   * @throws \Exception
   */
  public function refreshToken();

  /**
   * Helper callback for OAuth handshake, and refreshToken()
   *
   * @param GuzzleHttp\Psr7\Response $response
   * @param \GuzzleHttp\Psr7\Response $response
   *   Response object from refreshToken or authToken endpoints.
   *
   * @see SalesforceController::oauthCallback()
@@ -192,7 +192,7 @@ interface RestClientInterface {
   * @param string $id
   *   Identity URL.
   *
   * @throws Exception
   * @throws \Exception
   */
  public function initializeIdentity($id);

@@ -215,7 +215,7 @@ interface RestClientInterface {
   * @return string
   *   Redirect URL.
   *
   * @see Drupal\salesforce\Controller\SalesforceController
   * @see \Drupal\salesforce\Controller\SalesforceController
   */
  public function getAuthCallbackUrl();

@@ -291,14 +291,14 @@ interface RestClientInterface {
  public function queryMore(SelectQueryResult $results);

  /**
   * Retreieve all the metadata for an object.
   * Retrieve all the metadata for an object.
   *
   * @param string $name
   *   Object type name, E.g., Contact, Account, etc.
   * @param bool $reset
   *   Whether to reset the cache and retrieve a fresh version from Salesforce.
   *
   * @return RestResponse_Describe
   * @return \Drupal\salesforce\Rest\RestResponse_Describe
   *
   * @addtogroup salesforce_apicalls
   */
@@ -312,7 +312,7 @@ interface RestClientInterface {
   * @param array $params
   *   Values of the fields to set for the object.
   *
   * @return Drupal\salesforce\SFID
   * @return \Drupal\salesforce\SFID
   *
   * @addtogroup salesforce_apicalls
   */
@@ -334,7 +334,7 @@ interface RestClientInterface {
   * @param array $params
   *   Values of the fields to set for the object.
   *
   * @return Drupal\salesforce\SFID or NULL
   * @return \Drupal\salesforce\SFID|null
   *
   * @addtogroup salesforce_apicalls
   */
@@ -365,7 +365,7 @@ interface RestClientInterface {
   * @param string $id
   *   Salesforce id of the object.
   *
   * @return SObject
   * @return \Drupal\salesforce\SObject
   *   Object of the requested Salesforce object.
   *
   * @addtogroup salesforce_apicalls
@@ -382,7 +382,7 @@ interface RestClientInterface {
   * @param string $value
   *   Value of external id.
   *
   * @return SObject
   * @return \Drupal\salesforce\SObject
   *   Object of the requested Salesforce object.
   *
   * @addtogroup salesforce_apicalls
@@ -397,7 +397,6 @@ interface RestClientInterface {
   *   Object type name, E.g., Contact, Account.
   * @param string $id
   *   Salesforce id of the object.
   *
   * @pararm bool $throw_exception
   *   (optional) If TRUE, 404 response code will cause RequestException to be
   *   thrown. Otherwise, hide those errors. Default is FALSE.
@@ -427,7 +426,7 @@ interface RestClientInterface {
  /**
   * Return a list of available resources for the configured API version.
   *
   * @return Drupal\salesforce\Rest\RestResponse_Resources
   * @return \Drupal\salesforce\Rest\RestResponse_Resources
   *
   * @addtogroup salesforce_apicalls
   */
@@ -439,11 +438,9 @@ interface RestClientInterface {
   *
   * @param string $name
   *   Object type name, E.g., Contact, Account.
   *
   * @param int $start
   *   Unix timestamp for older timeframe for updates.
   *   Defaults to "-29 days" if empty.
   *
   * @param int $end
   *   unix timestamp for end of timeframe for updates.
   *   Defaults to now if empty.
@@ -488,7 +485,7 @@ interface RestClientInterface {
   * @return \Drupal\salesforce\SFID
   *   The Salesforce ID of the given Record Type, or null.
   *
   * @throws Exception if record type not found
   * @throws \Exception if record type not found
   */
  public function getRecordTypeIdByDeveloperName($name, $devname, $reset = FALSE);

@@ -499,7 +496,7 @@ interface RestClientInterface {
   *
   * @return string
   *
   * @throws Exception if SFID doesn't match any object type
   * @throws \Exception if SFID doesn't match any object type
   */
  public function getObjectTypeName(SFID $id);

+10 −3
Changes for src/Rest/RestException.php: 10 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -6,14 +6,21 @@ use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * Class RestException.
 *
 * @package Drupal\salesforce\Rest
 */
class RestException extends \RuntimeException implements ExceptionInterface {

  protected $response;

  /**
   * RestException constructor.
   *
   * @param \Psr\Http\Message\ResponseInterface|NULL $response
   * @param string $message
   * @param int $code
   * @param \Exception|NULL $previous
   */
  public function __construct(ResponseInterface $response = NULL, $message = "", $code = 0, \Exception $previous = NULL) {
    $this->response = $response;
@@ -22,18 +29,18 @@ class RestException extends \RuntimeException implements ExceptionInterface {
  }

  /**
   *
   * @return NULL|\Psr\Http\Message\ResponseInterface
   */
  public function getResponse() {
    return $this->response;
  }

  /**
   *
   * @return string|null
   */
  public function getResponseBody() {
    if (!$this->response) {
      return;
      return NULL;
    }
    $body = $this->response->getBody();
    if ($body) {
Loading