Test Failed
Branch master (cd3a65)
by Vincent
11:52
created

fr.quatrevieux.araknemu.game.fight.ai.proxy.ProxyPassiveFighter   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 81
Duplicated Lines 16.05 %

Test Coverage

Coverage 95.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
dl 13
loc 81
ccs 20
cts 21
cp 0.9524
rs 10
c 1
b 0
f 0
wmc 15

13 Methods

Rating   Name   Duplication   Size   Complexity  
A move(FightCell) 0 3 1
A buffs() 0 3 1
A states() 0 3 1
A life() 0 3 1
A id() 0 3 1
A cell() 0 3 1
A ProxyPassiveFighter(PassiveFighter,AI) 0 3 1
A hashCode() 0 3 1
A level() 0 3 1
A dead() 0 3 1
A team() 0 3 1
A equals(Object) 13 13 3
A characteristics() 0 3 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
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2021 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.fight.ai.proxy;
21
22
import fr.quatrevieux.araknemu.game.fight.ai.AI;
23
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buffs;
24
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
25
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
26
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
27
import fr.quatrevieux.araknemu.game.fight.fighter.States;
28
import fr.quatrevieux.araknemu.game.fight.map.FightCell;
29
import fr.quatrevieux.araknemu.game.fight.team.Team;
30
31
/**
32
 * Proxy class for override properties of other fighters
33
 *
34
 * Note: this object is immutable
35
 */
36
public final class ProxyPassiveFighter implements PassiveFighter {
37
    private final PassiveFighter fighter;
38
    private final AI ai;
39
40
    /**
41
     * @param fighter The fighter to wrap
42
     * @param ai The AI instance use to resolve the cell instance
43
     */
44 1
    public ProxyPassiveFighter(PassiveFighter fighter, AI ai) {
45 1
        this.fighter = fighter;
46 1
        this.ai = ai;
47 1
    }
48
49
    @Override
50
    public int id() {
51 1
        return fighter.id();
52
    }
53
54
    @Override
55
    public FightCell cell() {
56 1
        return ai.map().get(fighter.cell().id());
57
    }
58
59
    @Override
60
    public void move(FightCell cell) {
61 1
        throw new UnsupportedOperationException("This is a proxy fighter");
62
    }
63
64
    @Override
65
    public FighterLife life() {
66 1
        return fighter.life();
67
    }
68
69
    @Override
70
    public Buffs buffs() {
71 1
        return fighter.buffs();
72
    }
73
74
    @Override
75
    public States states() {
76 1
        return fighter.states();
77
    }
78
79
    @Override
80
    public int level() {
81
        return fighter.level();
82
    }
83
84
    @Override
85
    public FighterCharacteristics characteristics() {
86 1
        return fighter.characteristics();
87
    }
88
89
    @Override
90
    public Team<? extends PassiveFighter> team() {
91 1
        return fighter.team();
92
    }
93
94
    @Override
95
    public boolean dead() {
96 1
        return fighter.dead();
97
    }
98
99 View Code Duplication
    @Override
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
100
    public boolean equals(Object o) {
101 1
        if (this == o) {
102 1
            return true;
103
        }
104
105 1
        if (!(o instanceof PassiveFighter)) {
106 1
            return false;
107
        }
108
109 1
        final PassiveFighter that = (PassiveFighter) o;
110
111 1
        return id() == that.id();
112
    }
113
114
    @Override
115
    public int hashCode() {
116 1
        return fighter.hashCode();
117
    }
118
}
119