Completed
Push — master ( a33641...7233dc )
by San
02:42
created

Html   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 80 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 24
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
getSession() 0 1 ?
A countElements() 12 12 2
A findElement() 12 12 2

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 Behatch;
4
5
use Behat\MinkExtension\Context\RawMinkContext;
6
7
trait Html
8
{
9
    abstract protected function getSession($name = null);
10
11 View Code Duplication
    protected function countElements($element, $index, $parent)
12
    {
13
        $page = $this->getSession()->getPage();
14
15
        $parents = $page->findAll('css', $parent);
16
        if (!isset($parents[$index - 1])) {
17
            throw new \Exception("The $index element '$parent' was not found anywhere in the page");
18
        }
19
20
        $elements = $parents[$index - 1]->findAll('css', $element);
21
        return count($elements);
22
    }
23
24 View Code Duplication
    protected function findElement($selector, $locator, $index)
25
    {
26
        $page = $this->getSession()->getPage();
27
28
        $nodes = $page->findAll($selector, $locator);
29
30
        if (!isset($nodes[$index - 1])) {
31
            throw new \Exception("The $index $selector '$locator' was not found anywhere in the page");
32
        }
33
34
        return $nodes[$index - 1];
35
    }
36
}
37