ManagerTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 113
Duplicated Lines 14.16 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 6
dl 16
loc 113
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testGetTeam() 0 4 1
A testSetAndGetTeam() 0 7 1
A testTransferFactors() 0 5 1
A testDefensiveMoneyTransferFactor() 0 6 1
A testAcceptTransferOffer() 8 8 1
A testDenyTransferOffer() 8 8 1
B testSelectBestFittingPlayer() 0 24 1
A testCreateTransferOffer() 0 20 1
A assertTransferFactorMoneyBehaviour() 0 5 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\Manager;
6
use OSS\CoreBundle\Entity\Player;
7
use OSS\CoreBundle\Entity\PlayerSkills;
8
use OSS\CoreBundle\Entity\Team;
9
10
class ManagerTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Manager
14
     */
15
    private $manager;
16
17
    public function setUp()
18
    {
19
        $this->manager = new Manager();
20
    }
21
22
    public function tearDown()
23
    {
24
        $this->manager = null;
25
    }
26
27
    public function testGetTeam()
28
    {
29
        $this->assertNull($this->manager->getTeam());
30
    }
31
32
    public function testSetAndGetTeam()
33
    {
34
        $team = new Team();
35
        $this->manager->setTeam($team);
36
        $this->assertEquals($team, $this->manager->getTeam());
37
        $this->assertEquals($this->manager, $team->getManager());
38
    }
39
40
    public function testTransferFactors()
41
    {
42
        $allFactors = $this->manager->getTransferFactorTackling() + $this->manager->getTransferFactorPassing() + $this->manager->getTransferFactorShooting() + $this->manager->getTransferFactorHeading() + $this->manager->getTransferFactorSpeed() + $this->manager->getTransferFactorCrossing() + $this->manager->getTransferFactorTechnics() + $this->manager->getTransferFactorIntelligence() + $this->manager->getTransferFactorSafety() + $this->manager->getTransferFactorDribbling();
43
        $this->assertEquals(100, $allFactors);
44
    }
45
46
    public function testDefensiveMoneyTransferFactor()
47
    {
48
        $this->assertTransferFactorMoneyBehaviour(1, Manager::MONEY_BEHAVIOUR_NEUTRAL);
49
        $this->assertTransferFactorMoneyBehaviour(2, Manager::MONEY_BEHAVIOUR_DEFENSIVE);
50
        $this->assertTransferFactorMoneyBehaviour(0.5, Manager::MONEY_BEHAVIOUR_OFFENSIVE);
51
    }
52
53 View Code Duplication
    public function testAcceptTransferOffer()
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...
54
    {
55
        $this->manager->setAcceptTransferScoreOffset(100);
56
        $this->assertTrue($this->manager->acceptTransferOffer(150));
57
        $this->assertTrue($this->manager->acceptTransferOffer(100));
58
        $this->assertFalse($this->manager->acceptTransferOffer(99));
59
        $this->assertFalse($this->manager->acceptTransferOffer(50));
60
    }
61
62 View Code Duplication
    public function testDenyTransferOffer()
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...
63
    {
64
        $this->manager->setDenyTransferScoreOffset(50);
65
        $this->assertTrue($this->manager->denyTransferOffer(25));
66
        $this->assertTrue($this->manager->denyTransferOffer(50));
67
        $this->assertFalse($this->manager->denyTransferOffer(51));
68
        $this->assertFalse($this->manager->denyTransferOffer(100));
69
    }
70
71
    public function testSelectBestFittingPlayer()
72
    {
73
        $team = new Team();
74
        $team->setId(1);
75
        $team->setMoney(10);
76
        $player1 = new Player();
77
        $this->manager->setTeam($team);
78
        $skills1 = new PlayerSkills();
79
        $skills1->setAll(10);
80
        $player1->setId(1);
81
        $player1->setTeam($team);
82
        $player1->setSkills($skills1);
83
        $players = array($player1);
84
85
        $this->assertNull($this->manager->selectBestFittingPlayer($players));
86
87
        $skills2 = new PlayerSkills();
88
        $skills2->setAll(20);
89
        $player2 = new Player();
90
        $player2->setId(2);
91
        $player2->setSkills($skills2);
92
        $players[] = $player2;
93
        $this->assertEquals($player2, $this->manager->selectBestFittingPlayer($players));
94
    }
95
96
    public function testCreateTransferOffer()
97
    {
98
        $originTeam = new Team();
99
        $targetTeam = new Team();
100
101
        $this->manager->setTeam($targetTeam);
102
103
        $skills = new PlayerSkills();
104
        $skills->setAll(10);
105
106
        $player = new Player();
107
        $player->setSkills($skills);
108
        $player->setTeam($originTeam);
109
110
        $transferOffer = $this->manager->createTransferOffer($player);
111
        $this->assertEquals($originTeam, $transferOffer->getOriginTeam());
112
        $this->assertEquals($targetTeam, $transferOffer->getTargetTeam());
113
        $this->assertEquals($player, $transferOffer->getPlayer());
114
        $this->assertEquals(100, $transferOffer->getAmount());
115
    }
116
117
    private function assertTransferFactorMoneyBehaviour($factor, $moneyBehaviour)
118
    {
119
        $this->manager->setMoneyBehaviour($moneyBehaviour);
120
        $this->assertEquals($factor, $this->manager->getTransferFactorMoneyBehaviour());
121
    }
122
}
123