Completed
Push — master ( 910aee...a67276 )
by Dmitry
03:24
created

View   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 18
loc 78
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A visitTicket() 0 9 1
A postComment() 0 11 1
A seePreviewWorks() 0 7 1
A seePageContainsComment() 0 6 1
A closeTicket() 9 9 1
A openTicket() 9 9 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 hipanel\modules\ticket\tests\_support\Page\ticket;
4
5
use hipanel\tests\_support\AcceptanceTester;
6
use hipanel\tests\_support\Page\Authenticated;
7
use yii\helpers\Url;
8
9
/**
10
 * Class View
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class View extends Authenticated
15
{
16
    const THREAD_ID_SELECTOR = '.leave-comment-form input[name="Thread[id]"]';
17
18
    /**
19
     * @var string|int
20
     */
21
    private $ticketId;
22
23
    /**
24
     * View constructor.
25
     * @param \AcceptanceTester $I
26
     * @param string|int $ticketId
27
     */
28
    public function __construct(AcceptanceTester $I, $ticketId)
29
    {
30
        parent::__construct($I);
31
32
        $this->ticketId = $ticketId;
33
    }
34
35
    public function visitTicket()
36
    {
37
        $I = $this->tester;
38
39
        $I->amOnPage(Url::to(['@ticket/view', 'id' => $this->ticketId]));
40
        $I->seeInField(self::THREAD_ID_SELECTOR, $this->ticketId);
41
42
        return $this;
43
    }
44
45
    public function postComment($message)
46
    {
47
        $I = $this->tester;
48
49
        $I->fillField('#thread-message', $message);
50
        $this->seePreviewWorks($message);
51
52
        $I->click('Answer', '#leave-comment-form');
53
        $I->waitForText('Ticket changed');
54
        $this->seePageContainsComment($message);
55
    }
56
57
    protected function seePreviewWorks($message)
58
    {
59
        $I = $this->tester;
60
61
        $I->click('a[href="#preview-leave-comment-form"]');
62
        $I->waitForText($message, 10, '#preview-leave-comment-form');
63
    }
64
65
    protected function seePageContainsComment($message)
66
    {
67
        $I = $this->tester;
68
69
        $I->see($message, '.comment .comment-text .body');
70
    }
71
72 View Code Duplication
    public function closeTicket()
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...
73
    {
74
        $I = $this->tester;
75
76
        $I->see('Close ticket');
77
        $I->click('Close ticket');
78
        $I->waitForText('Ticket closed');
79
        $I->waitForText('Open ticket', 3);
80
    }
81
82 View Code Duplication
    public function openTicket()
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...
83
    {
84
        $I = $this->tester;
85
86
        $I->see('Open ticket');
87
        $I->click('Open ticket');
88
        $I->waitForText('Ticket opened');
89
        $I->waitForText('Close ticket', 3);
90
    }
91
}
92