Failed Conditions
Push — master ( b9670c...4ba57f )
by Zac
16:20 queued 37s
created

ChangeAlertSettingTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 12
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 12 12 1
A testChangeSetting() 0 12 1
A getSettingLink() 0 12 2
A getSettingRow() 0 6 1

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 Overwatch\UserBundle\Tests\E2E;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Overwatch\UserBundle\Tests\Base\WebDriverTestCase;
7
8
/**
9
 * ChangeAlertSettingTest
10
 * Tests Change Alert Settings Screen
11
 */
12
class ChangeAlertSettingTest extends WebDriverTestCase
13
{
14 View Code Duplication
    public function setUp()
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...
15
    {
16
        parent::setUp();
17
        
18
        $this->logInAsUser('user-1');
19
        $this->waitForLoadingAnimation();
20
        
21
        $this->webDriver->findElement(
22
            WebDriverBy::cssSelector('#sidebar li:nth-child(3) a')
23
        )->click();
24
        $this->waitForLoadingAnimation();
25
    }
26
    
27
    public function testChangeSetting()
28
    {
29
        $this->assertFalse($this->getSettingLink(5)->isDisplayed());
30
        $this->assertTrue($this->getSettingLink(5, true)->isDisplayed());
31
        
32
        $this->getSettingLink(1)->click();
33
        $this->waitForLoadingAnimation();
34
        $this->assertTrue($this->getSettingLink(5)->isDisplayed());
35
        $this->assertFalse($this->getSettingLink(5, true)->isDisplayed());
36
        $this->assertFalse($this->getSettingLink(1)->isDisplayed());
37
        $this->assertTrue($this->getSettingLink(1, true)->isDisplayed());
38
    }
39
    
40
    private function getSettingLink($number, $isCurrent = false)
41
    {
42
        $selector = '[data-ng-click]';
43
        
44
        if ($isCurrent) {
45
            $selector = ":not($selector)";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $selector instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
46
        }
47
        
48
        return $this->getSettingRow($number)->findElement(
49
            WebDriverBy::cssSelector("a$selector")
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $selector instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
50
        );
51
    }
52
    
53
    private function getSettingRow($number)
54
    {
55
        return $this->webDriver->findElement(
56
            WebDriverBy::cssSelector(".settings li:nth-child($number)")
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $number instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
57
        );
58
    }
59
}
60