Completed
Push — 62-logout-performance ( 400382...858f9a )
by Jonathan
01:37
created

DrupalSubContextBase::getContext()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.2
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\DrupalExtension\Context\DrupalSubContextBase.
6
 */
7
8
namespace Drupal\DrupalExtension\Context;
9
10
use Drupal\DrupalDriverManager;
11
12
/**
13
 * Base class for subcontexts that use the Drupal API.
14
 */
15
abstract class DrupalSubContextBase extends RawDrupalContext implements DrupalSubContextInterface
16
{
17
18
  /**
19
   * The Drupal Driver Manager.
20
   *
21
   * @var \Drupal\DrupalDriverManager $drupal
22
   */
23
    protected $drupal;
24
25
  /**
26
   * Constructs a DrupalSubContextBase object.
27
   *
28
   * @param \Drupal\DrupalDriverManager $drupal
29
   *   The Drupal driver manager.
30
   */
31
    public function __construct(DrupalDriverManager $drupal)
32
    {
33
        $this->drupal = $drupal;
34
    }
35
36
  /**
37
   * Get the currently logged in user from DrupalContext.
38
   *
39
   * @deprecated
40
   *   Deprecated in 4.x, will be removed before 5.x.
41
   *   The currently logged in user is now available in all context classes.
42
   *   Use $this->getUserManager()->getCurrentUser() instead.
43
   */
44
    protected function getUser()
45
    {
46
        trigger_error('DrupalSubContextBase::getUser() is deprecated. Use RawDrupalContext::getUserManager()->getCurrentUser() instead.', E_USER_DEPRECATED);
47
48
        $user = $this->getUserManager()->getCurrentUser();
49
50
        if (empty($user)) {
51
            throw new \Exception('No user is logged in.');
52
        }
53
54
        return $user;
55
    }
56
}
57