Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Transformation / Context / Annotation / TransformationAnnotationReader.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\Context\Annotation;
12
13 use Behat\Behat\Context\Annotation\AnnotationReader;
14 use Behat\Behat\Transformation\Transformation\PatternTransformation;
15 use Behat\Behat\Transformation\Transformation;
16 use ReflectionMethod;
17
18 /**
19  * Step transformation annotation reader.
20  *
21  * Reads step transformations from a context method annotation.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 class TransformationAnnotationReader implements AnnotationReader
26 {
27     /**
28      * @var string
29      */
30     private static $regex = '/^\@transform\s*+(.*+)$/i';
31
32     /**
33      * Loads step callees (if exist) associated with specific method.
34      *
35      * @param string           $contextClass
36      * @param ReflectionMethod $method
37      * @param string           $docLine
38      * @param string           $description
39      *
40      * @return null|Transformation
41      */
42     public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description)
43     {
44         if (!preg_match(self::$regex, $docLine, $match)) {
45             return null;
46         }
47
48         $pattern = $match[1];
49         $callable = array($contextClass, $method->getName());
50
51         foreach ($this->simpleTransformations() as $transformation) {
52             if ($transformation::supportsPatternAndMethod($pattern, $method)) {
53                 return new $transformation($pattern, $callable, $description);
54             }
55         }
56
57         return new PatternTransformation($pattern, $callable, $description);
58     }
59
60     /**
61      * Returns list of default transformations.
62      *
63      * @return array
64      */
65     private function simpleTransformations()
66     {
67         $transformations = array();
68         $transformations[] = 'Behat\Behat\Transformation\Transformation\RowBasedTableTransformation';
69         $transformations[] = 'Behat\Behat\Transformation\Transformation\ColumnBasedTableTransformation';
70         $transformations[] = 'Behat\Behat\Transformation\Transformation\TableRowTransformation';
71
72         if (PHP_VERSION_ID >= 70000) {
73             $transformations[] = 'Behat\Behat\Transformation\Transformation\TokenNameAndReturnTypeTransformation';
74             $transformations[] = 'Behat\Behat\Transformation\Transformation\ReturnTypeTransformation';
75         }
76
77         $transformations[] = 'Behat\Behat\Transformation\Transformation\TokenNameTransformation';
78
79         return $transformations;
80     }
81 }