You are here

class ReturnArgumentPromise in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnArgumentPromise.php \Prophecy\Promise\ReturnArgumentPromise

Return argument promise.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

Expanded class hierarchy of ReturnArgumentPromise

File

vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnArgumentPromise.php, line 23

Namespace

Prophecy\Promise
View source
class ReturnArgumentPromise implements PromiseInterface {

  /**
   * @var int
   */
  private $index;

  /**
   * Initializes callback promise.
   *
   * @param int $index The zero-indexed number of the argument to return
   *
   * @throws \Prophecy\Exception\InvalidArgumentException
   */
  public function __construct($index = 0) {
    if (!is_int($index) || $index < 0) {
      throw new InvalidArgumentException('Zero-based index expected as argument to ReturnArgumentPromise, but got %s.', $index);
    }
    $this->index = $index;
  }

  /**
   * Returns nth argument if has one, null otherwise.
   *
   * @param array          $args
   * @param ObjectProphecy $object
   * @param MethodProphecy $method
   *
   * @return null|mixed
   */
  public function execute(array $args, ObjectProphecy $object, MethodProphecy $method) {
    return count($args) > $this->index ? $args[$this->index] : null;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReturnArgumentPromise::$index private property
ReturnArgumentPromise::execute public function Returns nth argument if has one, null otherwise. Overrides PromiseInterface::execute
ReturnArgumentPromise::__construct public function Initializes callback promise.