Completed
Push — 1.0.x ( 0a17d9...7f19ee )
by Antonio
06:30
created

VisibilityContext   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 69.39 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 4
dl 34
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B iShouldSeeTheField() 17 17 5
B iShouldNotSeeTheField() 17 17 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace NuvoleWeb\Drupal\DrupalExtension\Context;
4
5
use Behat\Mink\Exception\UnsupportedDriverActionException;
6
7
/**
8
 * Class VisibilityContext.
9
 *
10
 * @package NuvoleWeb\Drupal\DrupalExtension\Context
11
 */
12
class VisibilityContext extends RawMinkContext {
13
14
  /**
15
   * Assert presence of given field on the page.
16
   *
17
   * @Then I should see the field :field
18
   */
19 View Code Duplication
  public function iShouldSeeTheField($field) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    $element = $this->getSession()->getPage();
21
    $result = $element->findField($field);
22
    try {
23
      if ($result && !$result->isVisible()) {
24
        throw new \Exception(sprintf("No field '%s' on the page %s", $field, $this->getSession()->getCurrentUrl()));
25
      }
26
    }
27
    catch (UnsupportedDriverActionException $e) {
28
      // We catch the UnsupportedDriverActionException exception in case
29
      // this step is not being performed by a driver that supports javascript.
30
      // All other exceptions are valid.
31
    }
32
    if (empty($result)) {
33
      throw new \Exception(sprintf("No field '%s' on the page %s", $field, $this->getSession()->getCurrentUrl()));
34
    }
35
  }
36
37
  /**
38
   * Assert absence of given field.
39
   *
40
   * @Then I should not see the field :field
41
   */
42 View Code Duplication
  public function iShouldNotSeeTheField($field) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    $element = $this->getSession()->getPage();
44
    $result = $element->findField($field);
45
    try {
46
      if ($result && $result->isVisible()) {
47
        throw new \Exception(sprintf("The field '%s' was present on the page %s and was not supposed to be", $field, $this->getSession()->getCurrentUrl()));
48
      }
49
    }
50
    catch (UnsupportedDriverActionException $e) {
51
      // We catch the UnsupportedDriverActionException exception in case
52
      // this step is not being performed by a driver that supports javascript.
53
      // All other exceptions are valid.
54
      if ($result) {
55
        throw new \Exception(sprintf("The field '%s' was present on the page %s and was not supposed to be", $field, $this->getSession()->getCurrentUrl()));
56
      }
57
    }
58
  }
59
60
}
61