You are here

final class VerificationResult in Commerce Core 8.2

Represents a tax number verification result.

Hierarchy

Expanded class hierarchy of VerificationResult

8 files declare their use of VerificationResult
EuropeanUnionVatTest.php in modules/tax/tests/src/Kernel/Plugin/Commerce/TaxNumberType/EuropeanUnionVatTest.php
SerbianVat.php in modules/tax/tests/modules/commerce_tax_test/src/Plugin/Commerce/TaxNumberType/SerbianVat.php
TaxNumberController.php in modules/tax/src/Controller/TaxNumberController.php
TaxNumberDefaultFormatter.php in modules/tax/src/Plugin/Field/FieldFormatter/TaxNumberDefaultFormatter.php
TaxNumberItem.php in modules/tax/src/Plugin/Field/FieldType/TaxNumberItem.php

... See full list

File

modules/tax/src/Plugin/Commerce/TaxNumberType/VerificationResult.php, line 8

Namespace

Drupal\commerce_tax\Plugin\Commerce\TaxNumberType
View source
final class VerificationResult {

  /**
   * Available states.
   */
  const STATE_SUCCESS = 'success';
  const STATE_FAILURE = 'failure';
  const STATE_UNKNOWN = 'unknown';

  /**
   * The state.
   *
   * One of the STATE_ constants.
   *
   * @var string
   */
  protected $state;

  /**
   * The timestamp.
   *
   * @var int
   */
  protected $timestamp;

  /**
   * The data.
   *
   * @var string
   */
  protected $data;

  /**
   * Constructs a new VerificationResult object.
   *
   * @param string $state
   *   The state. One of the STATE_ constants.
   * @param int $timestamp
   *   The timestamp.
   * @param array $data
   *   The data. Optional.
   */
  public function __construct(string $state, int $timestamp, array $data = []) {
    $this->state = $state;
    $this->timestamp = $timestamp;
    $this->data = $data;
  }

  /**
   * Constructs a success result.
   *
   * @param int $timestamp
   *   The timestamp.
   * @param array $data
   *   The data. Optional.
   *
   * @return static
   */
  public static function success(int $timestamp, array $data = []) : VerificationResult {
    return new static(self::STATE_SUCCESS, $timestamp, $data);
  }

  /**
   * Constructs a failure result.
   *
   * @param int $timestamp
   *   The timestamp.
   * @param array $data
   *   The data. Optional.
   *
   * @return static
   */
  public static function failure(int $timestamp, array $data = []) : VerificationResult {
    return new static(self::STATE_FAILURE, $timestamp, $data);
  }

  /**
   * Constructs an unkown result.
   *
   * @param int $timestamp
   *   The timestamp.
   * @param array $data
   *   The data. Optional.
   *
   * @return static
   */
  public static function unknown(int $timestamp, array $data = []) : VerificationResult {
    return new static(self::STATE_UNKNOWN, $timestamp, $data);
  }

  /**
   * Gets whether the verification was successful.
   *
   * @return bool
   *   TRUE if the verification was successful, FALSE otherwise.
   */
  public function isSuccess() : bool {
    return $this->state == self::STATE_SUCCESS;
  }

  /**
   * Gets whether the verification failed.
   *
   * @return bool
   *   TRUE if the verification failed, FALSE otherwise.
   */
  public function isFailure() : bool {
    return $this->state == self::STATE_FAILURE;
  }

  /**
   * Gets whether the verification state is unknown.
   *
   * Used for cases where the remote service is temporarily unavailable.
   *
   * @return bool
   *   TRUE if the verification state is unknown, FALSE otherwise.
   */
  public function isUnknown() : bool {
    return $this->state == self::STATE_UNKNOWN;
  }

  /**
   * Gets the state.
   *
   * @return string
   *   The state. One of the STATE_ constants.
   */
  public function getState() : string {
    return $this->state;
  }

  /**
   * Gets the timestamp.
   *
   * @return int
   *   The timestamp.
   */
  public function getTimestamp() : int {
    return $this->timestamp;
  }

  /**
   * Gets the data.
   *
   * @return array
   *   The data.
   */
  public function getData() : array {
    return $this->data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
VerificationResult::$data protected property The data.
VerificationResult::$state protected property The state.
VerificationResult::$timestamp protected property The timestamp.
VerificationResult::failure public static function Constructs a failure result.
VerificationResult::getData public function Gets the data.
VerificationResult::getState public function Gets the state.
VerificationResult::getTimestamp public function Gets the timestamp.
VerificationResult::isFailure public function Gets whether the verification failed.
VerificationResult::isSuccess public function Gets whether the verification was successful.
VerificationResult::isUnknown public function Gets whether the verification state is unknown.
VerificationResult::STATE_FAILURE constant
VerificationResult::STATE_SUCCESS constant Available states.
VerificationResult::STATE_UNKNOWN constant
VerificationResult::success public static function Constructs a success result.
VerificationResult::unknown public static function Constructs an unkown result.
VerificationResult::__construct public function Constructs a new VerificationResult object.