TrainerTest   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 144
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 4
dl 32
loc 144
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 5 1
A testSkill() 0 4 1
A testSetAndGetSkill() 0 5 1
A testGetTeam() 0 4 1
A testSetAndGetTeam() 0 7 1
A testGetId() 0 4 1
A testSetAndGetId() 0 5 1
A testGetName() 0 4 1
A testSetAndGetName() 0 5 1
A testTrainingFactors() 0 5 1
A testTrainWithSkill1() 0 14 1
A testTrainWithSkill1AndBaseValue() 16 16 1
A testTrainWithSkill50() 16 16 1
A testTrainBySpecializedTrainerWithSkill100() 0 18 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 OSS\CoreBundle\Tests\Entity;
4
5
use OSS\CoreBundle\Entity\Player;
6
use OSS\CoreBundle\Entity\PlayerSkills;
7
use OSS\CoreBundle\Entity\Team;
8
use OSS\CoreBundle\Entity\Trainer;
9
10
class TrainerTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Trainer
14
     */
15
    private $trainer;
16
17
    /**
18
     * @var PlayerSkills
19
     */
20
    private $skills;
21
22
    public function setUp()
23
    {
24
        $this->trainer = new Trainer();
25
        $this->skills = new PlayerSkills();
26
    }
27
28
    public function tearDown()
29
    {
30
        $this->trainer = null;
31
        $this->skills = null;
32
    }
33
34
    public function testSkill()
35
    {
36
        $this->assertEquals(1, $this->trainer->getSkill());
37
    }
38
39
    public function testSetAndGetSkill()
40
    {
41
        $this->trainer->setSkill(100);
42
        $this->assertEquals(100, $this->trainer->getSkill());
43
    }
44
45
    public function testGetTeam()
46
    {
47
        $this->assertNull($this->trainer->getTeam());
48
    }
49
50
    public function testSetAndGetTeam()
51
    {
52
        $team = new Team();
53
        $this->trainer->setTeam($team);
54
        $this->assertEquals($team, $this->trainer->getTeam());
55
        $this->assertEquals($this->trainer, $team->getTrainer());
56
    }
57
58
    public function testGetId()
59
    {
60
        $this->assertNull($this->trainer->getId());
61
    }
62
63
    public function testSetAndGetId()
64
    {
65
        $this->trainer->setId(1);
66
        $this->assertEquals(1, $this->trainer->getId());
67
    }
68
69
    public function testGetName()
70
    {
71
        $this->assertNull($this->trainer->getName());
72
    }
73
74
    public function testSetAndGetName()
75
    {
76
        $this->trainer->setName('John Doe');
77
        $this->assertEquals('John Doe', $this->trainer->getName());
78
    }
79
    
80
    public function testTrainingFactors()
81
    {
82
        $allFactors = $this->trainer->getTrainingFactorTackling() + $this->trainer->getTrainingFactorPassing() + $this->trainer->getTrainingFactorShooting() + $this->trainer->getTrainingFactorHeading() + $this->trainer->getTrainingFactorSpeed() + $this->trainer->getTrainingFactorCrossing() + $this->trainer->getTrainingFactorTechnics() + $this->trainer->getTrainingFactorIntelligence() + $this->trainer->getTrainingFactorSafety() + $this->trainer->getTrainingFactorDribbling();
83
        $this->assertEquals(100, $allFactors);
84
    }
85
86
    public function testTrainWithSkill1()
87
    {
88
        $this->trainer->train($this->skills);
89
        $this->assertEquals(1, $this->skills->getTrainingValueTackling());
90
        $this->assertEquals(1, $this->skills->getTrainingValuePassing());
91
        $this->assertEquals(1, $this->skills->getTrainingValueShooting());
92
        $this->assertEquals(1, $this->skills->getTrainingValueHeading());
93
        $this->assertEquals(1, $this->skills->getTrainingValueSpeed());
94
        $this->assertEquals(1, $this->skills->getTrainingValueCrossing());
95
        $this->assertEquals(1, $this->skills->getTrainingValueTechnics());
96
        $this->assertEquals(1, $this->skills->getTrainingValueIntelligence());
97
        $this->assertEquals(1, $this->skills->getTrainingValueSafety());
98
        $this->assertEquals(1, $this->skills->getTrainingValueDribbling());
99
    }
100
101 View Code Duplication
    public function testTrainWithSkill1AndBaseValue()
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...
102
    {
103
        $this->skills->setAllTrainingValues(1);
104
105
        $this->trainer->train($this->skills);
106
        $this->assertEquals(2, $this->skills->getTrainingValueTackling());
107
        $this->assertEquals(2, $this->skills->getTrainingValuePassing());
108
        $this->assertEquals(2, $this->skills->getTrainingValueShooting());
109
        $this->assertEquals(2, $this->skills->getTrainingValueHeading());
110
        $this->assertEquals(2, $this->skills->getTrainingValueSpeed());
111
        $this->assertEquals(2, $this->skills->getTrainingValueCrossing());
112
        $this->assertEquals(2, $this->skills->getTrainingValueTechnics());
113
        $this->assertEquals(2, $this->skills->getTrainingValueIntelligence());
114
        $this->assertEquals(2, $this->skills->getTrainingValueSafety());
115
        $this->assertEquals(2, $this->skills->getTrainingValueDribbling());
116
    }
117
118 View Code Duplication
    public function testTrainWithSkill50()
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...
119
    {
120
        $this->trainer->setSkill(50);
121
122
        $this->trainer->train($this->skills);
123
        $this->assertEquals(25, $this->skills->getTrainingValueTackling());
124
        $this->assertEquals(25, $this->skills->getTrainingValuePassing());
125
        $this->assertEquals(25, $this->skills->getTrainingValueShooting());
126
        $this->assertEquals(25, $this->skills->getTrainingValueHeading());
127
        $this->assertEquals(25, $this->skills->getTrainingValueSpeed());
128
        $this->assertEquals(25, $this->skills->getTrainingValueCrossing());
129
        $this->assertEquals(25, $this->skills->getTrainingValueTechnics());
130
        $this->assertEquals(25, $this->skills->getTrainingValueIntelligence());
131
        $this->assertEquals(25, $this->skills->getTrainingValueSafety());
132
        $this->assertEquals(25, $this->skills->getTrainingValueDribbling());
133
    }
134
135
    public function testTrainBySpecializedTrainerWithSkill100()
136
    {
137
        $this->trainer->setSkill(100);
138
        $this->trainer->setTrainingFactorTackling(20);
139
        $this->trainer->setTrainingFactorPassing(0);
140
141
        $this->trainer->train($this->skills);
142
        $this->assertEquals(100, $this->skills->getTrainingValueTackling());
143
        $this->assertEquals(0, $this->skills->getTrainingValuePassing());
144
        $this->assertEquals(50, $this->skills->getTrainingValueShooting());
145
        $this->assertEquals(50, $this->skills->getTrainingValueHeading());
146
        $this->assertEquals(50, $this->skills->getTrainingValueSpeed());
147
        $this->assertEquals(50, $this->skills->getTrainingValueCrossing());
148
        $this->assertEquals(50, $this->skills->getTrainingValueTechnics());
149
        $this->assertEquals(50, $this->skills->getTrainingValueIntelligence());
150
        $this->assertEquals(50, $this->skills->getTrainingValueSafety());
151
        $this->assertEquals(50, $this->skills->getTrainingValueDribbling());
152
    }
153
}
154