GroupingTariffPlansCest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 64
loc 64
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureThatICanCreateTariffPlan() 14 14 1
A ensureThatICanSeeTariffPlan() 9 9 1
A ensureThatICanUpdateTariffPlan() 13 13 1
A ensureThatICanDeleteTariffPlan() 5 5 1
A ensureThatIDontSeeTariffPlan() 6 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 advancedhosters\hipanel\tests\acceptance\module\finance\manager;
4
5
use hipanel\modules\finance\tests\_support\Page\plan\CreateGrouping as Create;
6
use hipanel\modules\finance\tests\_support\Page\plan\View;
7
use hipanel\modules\finance\tests\_support\Page\plan\UpdateGrouping as Update;
8
use hipanel\modules\finance\tests\_support\Page\plan\Delete;
9
use hipanel\modules\finance\tests\_support\Page\plan\Index;
10
use hipanel\tests\_support\Step\Acceptance\Manager;
11
12 View Code Duplication
class GroupingTariffPlansCest
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    /**
15
     * @var string
16
     */
17
    private $id;
18
19
    /**
20
     * @var array
21
     */
22
    private $fields;
23
24
    public function ensureThatICanCreateTariffPlan(Manager $I)
25
    {
26
        $this->fields = [
27
            'name' => uniqid(),
28
            'type' => 'Template',
29
            'client' => 'hipanel_test_manager',
30
            'currency' => 'USD',
31
            'note' => 'test note',
32
        ];
33
        $plan = new Create($I, $this->fields);
34
        $plan->seeFields();
35
        $this->id = $plan->createPlan();
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type string, but $plan->createPlan() is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
36
        $this->ensureThatICanSeeTariffPlan($I);
37
    }
38
39
    private function ensureThatICanSeeTariffPlan(Manager $I)
40
    {
41
        $plan = new View($I, $this->fields, $this->id);
42
        $plan->visitPlan();
43
        $plan->seePlan();
44
        $search = new Index($I);
45
        $search->ensurePageWorks();
46
        $search->ensurePlanCanBeFound($this->fields['name']);
47
    }
48
49
    public function ensureThatICanUpdateTariffPlan(Manager $I)
50
    {
51
        $this->fields = [
52
            'name' => uniqid(),
53
            'type' => 'Server',
54
            'client' => 'hipanel_test_manager',
55
            'currency' => 'EUR',
56
            'note' => 'new_test_note',
57
        ];
58
        $plan = new Update($I, $this->fields);
59
        $this->id = $plan->updatePlan($this->id);
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type string, but $plan->updatePlan($this->id) is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
60
        $this->ensureThatICanSeeTariffPlan($I);
61
    }
62
63
    public function ensureThatICanDeleteTariffPlan(Manager $I)
64
    {
65
        (new Delete($I, null, $this->id))->deletePlan();
66
        $this->ensureThatIDontSeeTariffPlan($I);
67
    }
68
69
    private function ensureThatIDontSeeTariffPlan(Manager $I)
70
    {
71
        $search = new Index($I);
72
        $search->ensurePageWorks();
73
        $search->ensurePlanNotFound($this->fields['name']);
74
    }
75
}
76