TokensReplacementAnnotationReader::readCallee()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 4
1
<?php
2
3
/**
4
 * @author Alexei Gorobet <[email protected]>
5
 */
6
7
namespace Behat\TokensExtension\Context\Annotation;
8
9
use Behat\Behat\Context\Annotation\AnnotationReader;
10
use Behat\TokensExtension\Call\RuntimeTokensReplacement;
11
use ReflectionMethod;
12
13
/**
14
 * Step tokens replacement annotation reader.
15
 *
16
 * Reads step tokens replacements from a context method annotation.
17
 *
18
 * @author Alexei Gorobet <[email protected]>
19
 */
20
class TokensReplacementAnnotationReader implements AnnotationReader
21
{
22
    /**
23
     * @var string
24
     */
25
    private static $regex = '/^\@tokensreplacement\s+(.+)$/i';
26
27
    /**
28
     * Loads step callees (if exist) associated with specific method.
29
     *
30
     * @param string           $contextClass
31
     * @param ReflectionMethod $method
32
     * @param string           $docLine
33
     * @param string           $description
34
     *
35
     * @return null|RuntimeTokensReplacement
36
     */
37
    public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description)
38
    {
39
        if (!preg_match(self::$regex, $docLine, $match)) {
40
            return null;
41
        }
42
43
        $pattern = $match[1];
44
        $callable = array($contextClass, $method->getName());
0 ignored issues
show
Bug introduced by
Consider using $method->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
45
46
        return new RuntimeTokensReplacement($pattern, $callable, $description);
47
    }
48
}
49