Completed
Push — 3.2 ( 51a84d...abe3a3 )
by Jonathan
8s
created

Reader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A readCallee() 0 13 3
1
<?php
2
3
namespace Drupal\DrupalExtension\Context\Annotation;
4
5
use Behat\Behat\Context\Annotation\AnnotationReader;
6
use Drupal\DrupalExtension\Hook\Dispatcher;
7
use ReflectionMethod;
8
9
/**
10
 * Annotated contexts reader.
11
 *
12
 * @see \Behat\Behat\Context\Loader\AnnotatedLoader
13
 */
14
class Reader implements AnnotationReader {
15
16
  /**
17
   * @var string
18
   */
19
  private static $regex = '/^\@(beforenodecreate|afternodecreate|beforetermcreate|aftertermcreate|beforeusercreate|afterusercreate)(?:\s+(.+))?$/i';
20
21
  /**
22
   * @var string[]
23
   */
24
  private static $classes = array(
25
    'afternodecreate' => 'Drupal\DrupalExtension\Hook\Call\AfterNodeCreate',
26
    'aftertermcreate' => 'Drupal\DrupalExtension\Hook\Call\AfterTermCreate',
27
    'afterusercreate' => 'Drupal\DrupalExtension\Hook\Call\AfterUserCreate',
28
    'beforenodecreate' => 'Drupal\DrupalExtension\Hook\Call\BeforeNodeCreate',
29
    'beforetermcreate' => 'Drupal\DrupalExtension\Hook\Call\BeforeTermCreate',
30
    'beforeusercreate' => 'Drupal\DrupalExtension\Hook\Call\BeforeUserCreate',
31
  );
32
33
  /**
34
   * {@inheritDoc}
35
   */
36
  public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description) {
37
38
    if (!preg_match(self::$regex, $docLine, $match)) {
39
      return null;
40
    }
41
42
    $type = strtolower($match[1]);
43
    $class = self::$classes[$type];
44
    $pattern = isset($match[2]) ? $match[2] : null;
45
    $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...
46
47
    return new $class($pattern, $callable, $description);
48
  }
49
50
}
51