Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

ReturnArgumentPromise.php

Namespace

Prophecy\Promise

File

vendor/phpspec/prophecy/src/Prophecy/Promise/ReturnArgumentPromise.php

View source
<?php


/*
 * This file is part of the Prophecy.
 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
 *     Marcello Duarte <marcello.duarte@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Prophecy\Promise;

use Prophecy\Exception\InvalidArgumentException;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophecy\MethodProphecy;

/**
 * Returns nth argument if has one, null otherwise.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 */
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(sprintf('Zero-based index expected as argument to ReturnArgumentPromise, but got %s.', $index));
        }
        $this->index = $index;
    }
    public function execute(array $args, ObjectProphecy $object, MethodProphecy $method) {
        return count($args) > $this->index ? $args[$this->index] : null;
    }

}

Classes

Title Deprecated Summary
ReturnArgumentPromise Returns nth argument if has one, null otherwise.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal