Completed
Push — master ( 8158f1...90d7fd )
by Konstantinos
11:17 queued 06:55
created

ColorTeam   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 67
ccs 14
cts 14
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidTeamColor() 0 4 1
A __construct() 0 4 1
A getId() 0 4 1
A getName() 0 4 1
A getAvatar() 0 4 1
A isSameAs() 0 6 3
1
<?php
2
/**
3
 * This file contains functionality relating to the fun match teams
4
 *
5
 * @package    BZiON\Models
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
/**
10
 * A team identified by its color in BZFlag
11
 * @package    BZiON\Models
12
 */
13
class ColorTeam implements TeamInterface
14
{
15
    /**
16
     * The color of the team
17
     *
18
     * @var string
19
     */
20
    protected $color;
21
22
    /**
23
     * Define a new ColorTeam
24
     * @param string $color The color of the team
25
     */
26 1
    public function __construct($color)
27
    {
28 1
        $this->color = strtolower($color);
29 1
    }
30
31
    /**
32
     * Get a unique identifier for the team
33
     *
34
     * @return string
35
     */
36 1
    public function getId()
37
    {
38 1
        return $this->color;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function getName()
45
    {
46 1
        return ucwords($this->color) . " Team";
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function getAvatar()
53
    {
54 1
        return "assets/imgs/team_" . $this->color . ".png";
55
    }
56
57
    /**
58
     * Return whether a team color is valid
59
     *
60
     * @param string $color The color to check
61
     */
62 1
    public static function isValidTeamColor($color)
63
    {
64 1
        return in_array($color, array('red', 'green', 'blue', 'purple'));
65
    }
66
67
    /**
68
     * Find out if a team is the same as another team
69
     *
70
     * @param mixed $team The team to compare
71
     * @param bool
72
     */
73 1
    public function isSameAs($team)
74
    {
75 1
        $sameType = $this instanceof $team || $team instanceof $this;
76
77 1
        return $sameType && $this->color === $team->color;
78
    }
79
}
80