Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Transformation / Transformation / TokenNameAndReturnTypeTransformation.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Transformation\Transformation;
12
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;
18 use ReflectionMethod;
19
20 /**
21  * Name and return type object transformation.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class TokenNameAndReturnTypeTransformation extends RuntimeCallee implements SimpleArgumentTransformation
26 {
27     /**
28      * @var TokenNameTransformation
29      */
30     private $tokenTransformation;
31     /**
32      * @var ReturnTypeTransformation
33      */
34     private $returnTransformation;
35
36     /**
37      * {@inheritdoc}
38      */
39     static public function supportsPatternAndMethod($pattern, ReflectionMethod $method)
40     {
41         return TokenNameTransformation::supportsPatternAndMethod($pattern, $method)
42             && ReturnTypeTransformation::supportsPatternAndMethod('', $method);
43     }
44
45     /**
46      * Initializes transformation.
47      *
48      * @param string      $pattern
49      * @param callable    $callable
50      * @param null|string $description
51      */
52     public function __construct($pattern, $callable, $description = null)
53     {
54         $this->tokenTransformation = new TokenNameTransformation($pattern, $callable, $description);
55         $this->returnTransformation = new ReturnTypeTransformation('', $callable, $description);
56
57         parent::__construct($callable, $description);
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
64     {
65         return $this->tokenTransformation->supportsDefinitionAndArgument($definitionCall, $argumentIndex, $argumentValue)
66             && $this->returnTransformation->supportsDefinitionAndArgument($definitionCall, $argumentIndex, $argumentValue);
67     }
68
69     /**
70      * {@inheritdoc}
71      */
72     public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
73     {
74         $call = new TransformationCall(
75             $definitionCall->getEnvironment(),
76             $definitionCall->getCallee(),
77             $this,
78             array($argumentValue)
79         );
80
81         $result = $callCenter->makeCall($call);
82
83         if ($result->hasException()) {
84             throw $result->getException();
85         }
86
87         return $result->getReturn();
88     }
89
90     /**
91      * {@inheritdoc}
92      */
93     public function getPriority()
94     {
95         return 100;
96     }
97
98     /**
99      * {@inheritdoc}
100      */
101     public function getPattern()
102     {
103         return $this->tokenTransformation->getPattern();
104     }
105
106     /**
107      * {@inheritdoc}
108      */
109     public function __toString()
110     {
111         return 'NamedReturnTypeTransform ' . $this->getPattern();
112     }
113 }