Completed
Pull Request — 3.1 (#290)
by
unknown
09:17
created

RegionSelector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A translateToXPath() 0 8 2
1
<?php
2
3
namespace Drupal\DrupalExtension\Selector;
4
5
use Behat\Mink\Selector\SelectorInterface;
6
use Behat\Mink\Selector\CssSelector;
7
8
/**
9
 * Custom "region" selector to help select Drupal regions
10
 */
11
class RegionSelector implements SelectorInterface {
12
  private $cssSelector;
13
14
  private $regionMap;
15
16
  public function __construct(CssSelector $cssSelector, array $regionMap) {
17
    $this->cssSelector = $cssSelector;
18
    $this->regionMap = $regionMap;
19
  }
20
21
  /**
22
   * Translates provided locator into XPath.
23
   *
24
   * @param string $region
25
   * @return string
26
   * @throws \InvalidArgumentException
27
   */
28
  public function translateToXPath($region) {
29
    if (!isset($this->regionMap[$region])) {
30
      throw new \InvalidArgumentException(sprintf('The "%s" region isn\'t configured!', $region));
31
    }
32
    $css = $this->regionMap[$region];
33
34
    return $this->cssSelector->translateToXPath($css);
35
  }
36
}
37