4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Transformation\Transformation;
13 use Behat\Behat\Definition\Call\DefinitionCall;
14 use Behat\Behat\Transformation\Call\TransformationCall;
15 use Behat\Behat\Transformation\SimpleArgumentTransformation;
16 use Behat\Testwork\Call\CallCenter;
17 use Behat\Testwork\Call\RuntimeCallee;
21 * Name and return type object transformation.
23 * @author Konstantin Kudryashov <ever.zet@gmail.com>
25 final class TokenNameAndReturnTypeTransformation extends RuntimeCallee implements SimpleArgumentTransformation
28 * @var TokenNameTransformation
30 private $tokenTransformation;
32 * @var ReturnTypeTransformation
34 private $returnTransformation;
39 static public function supportsPatternAndMethod($pattern, ReflectionMethod $method)
41 return TokenNameTransformation::supportsPatternAndMethod($pattern, $method)
42 && ReturnTypeTransformation::supportsPatternAndMethod('', $method);
46 * Initializes transformation.
48 * @param string $pattern
49 * @param callable $callable
50 * @param null|string $description
52 public function __construct($pattern, $callable, $description = null)
54 $this->tokenTransformation = new TokenNameTransformation($pattern, $callable, $description);
55 $this->returnTransformation = new ReturnTypeTransformation('', $callable, $description);
57 parent::__construct($callable, $description);
63 public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
65 return $this->tokenTransformation->supportsDefinitionAndArgument($definitionCall, $argumentIndex, $argumentValue)
66 && $this->returnTransformation->supportsDefinitionAndArgument($definitionCall, $argumentIndex, $argumentValue);
72 public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
74 $call = new TransformationCall(
75 $definitionCall->getEnvironment(),
76 $definitionCall->getCallee(),
81 $result = $callCenter->makeCall($call);
83 if ($result->hasException()) {
84 throw $result->getException();
87 return $result->getReturn();
93 public function getPriority()
101 public function getPattern()
103 return $this->tokenTransformation->getPattern();
109 public function __toString()
111 return 'NamedReturnTypeTransform ' . $this->getPattern();