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

Breadcrumb

  1. Drupal Core 11.1.x

TypeToken.php

Namespace

Prophecy\Argument\Token

File

vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.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\Argument\Token;

use Prophecy\Exception\InvalidArgumentException;

/**
 * Value type token.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 */
class TypeToken implements TokenInterface {
    private $type;
    
    /**
     * @param string $type
     */
    public function __construct($type) {
        $checker = "is_{$type}";
        if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) {
            throw new InvalidArgumentException(sprintf('Type or class name expected as an argument to TypeToken, but got %s.', $type));
        }
        $this->type = $type;
    }
    
    /**
     * Scores 5 if argument has the same type this token was constructed with.
     *
     * @param $argument
     *
     * @return bool|int
     */
    public function scoreArgument($argument) {
        $checker = "is_{$this->type}";
        if (function_exists($checker)) {
            return call_user_func($checker, $argument) ? 5 : false;
        }
        return $argument instanceof $this->type ? 5 : false;
    }
    
    /**
     * Returns false.
     *
     * @return bool
     */
    public function isLast() {
        return false;
    }
    
    /**
     * Returns string representation for token.
     *
     * @return string
     */
    public function __toString() {
        return sprintf('type(%s)', $this->type);
    }

}

Classes

Title Deprecated Summary
TypeToken Value type token.

API Navigation

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