Completed
Push — eliza411-patch-1 ( a2be10 )
by
unknown
10:11
created

DrupalAwareInitializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A initializeContext() 0 16 2
1
<?php
2
3
namespace Drupal\DrupalExtension\Context\Initializer;
4
5
use Behat\Behat\Context\Initializer\ContextInitializer;
6
use Behat\Behat\Context\Context;
7
use Behat\Testwork\Hook\HookDispatcher;
8
9
use Drupal\DrupalDriverManager;
10
use Drupal\DrupalExtension\Context\DrupalContext;
11
use Drupal\DrupalExtension\Context\DrupalAwareInterface;
12
13
class DrupalAwareInitializer implements ContextInitializer {
14
  private $drupal, $parameters, $dispatcher;
15
16
  public function __construct(DrupalDriverManager $drupal, array $parameters, HookDispatcher $dispatcher) {
17
    $this->drupal = $drupal;
18
    $this->parameters = $parameters;
19
    $this->dispatcher = $dispatcher;
20
  }
21
22
  /**
23
   * {@inheritdocs}
24
   */
25
  public function initializeContext(Context $context) {
26
27
    // All contexts are passed here, only DrupalAwareInterface is allowed.
28
    if (!$context instanceof DrupalAwareInterface) {
29
      return;
30
    }
31
32
    // Set Drupal driver manager.
33
    $context->setDrupal($this->drupal);
34
35
    // Set event dispatcher.
36
    $context->setDispatcher($this->dispatcher);
37
38
    // Add all parameters to the context.
39
    $context->setDrupalParameters($this->parameters);
40
  }
41
42
}
43