class CallbackToken
Callback-verified token.
@author Konstantin Kudryashov <ever.zet@gmail.com>
Hierarchy
- class \Prophecy\Argument\Token\CallbackToken implements \Prophecy\Argument\Token\TokenInterface
Expanded class hierarchy of CallbackToken
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Argument/ Token/ CallbackToken.php, line 21
Namespace
Prophecy\Argument\TokenView source
class CallbackToken implements TokenInterface {
private $callback;
/**
* @var string|null
*/
private $customStringRepresentation;
/**
* Initializes token.
*
* @param callable $callback
* @param string|null $customStringRepresentation Customize the __toString() representation of this token
*
* @throws \Prophecy\Exception\InvalidArgumentException
*/
public function __construct($callback, ?string $customStringRepresentation = null) {
if (!is_callable($callback)) {
throw new InvalidArgumentException(sprintf('Callable expected as an argument to CallbackToken, but got %s.', gettype($callback)));
}
$this->callback = $callback;
$this->customStringRepresentation = $customStringRepresentation;
}
/**
* Scores 7 if callback returns true, false otherwise.
*
* @param mixed $argument
*
* @return false|int
*/
public function scoreArgument($argument) {
return call_user_func($this->callback, $argument) ? 7 : false;
}
/**
* Returns false.
*
* @return bool
*/
public function isLast() {
return false;
}
/**
* Returns string representation for token.
*
* @return string
*/
public function __toString() {
if ($this->customStringRepresentation !== null) {
return $this->customStringRepresentation;
}
return 'callback()';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
CallbackToken::$callback | private | property | ||
CallbackToken::$customStringRepresentation | private | property | ||
CallbackToken::isLast | public | function | Returns false. | Overrides TokenInterface::isLast |
CallbackToken::scoreArgument | public | function | Scores 7 if callback returns true, false otherwise. | Overrides TokenInterface::scoreArgument |
CallbackToken::__construct | public | function | Initializes token. | |
CallbackToken::__toString | public | function | Returns string representation for token. | Overrides TokenInterface::__toString |