Completed
Push — feature/player-elo ( 4b3aa9...88903f )
by Vladimir
03:15
created

ColorTeam::isLastMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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 4
    public function __construct($color)
27
    {
28 4
        $this->color = strtolower($color);
29 4
    }
30
31
    /**
32
     * Get a unique identifier for the team
33
     *
34
     * @return string
35
     */
36 4
    public function getId()
37
    {
38 4
        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
     * {@inheritdoc}
59
     */
60 4
    public function isValid()
61
    {
62 4
        return true;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 2
    public function isLastMatch($match)
69
    {
70 2
        return true;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function supportsMatchCount()
77
    {
78 1
        return false;
79
    }
80 1
81
    /**
82
     * Return whether a team color is valid
83
     *
84
     * @param string $color The color to check
85
     */
86
    public static function isValidTeamColor($color)
87
    {
88
        return in_array($color, array('red', 'green', 'blue', 'purple'));
89 1
    }
90
91 1
    /**
92
     * {@inheritdoc}
93 1
     */
94
    public function isSameAs($team)
95
    {
96
        $sameType = $this instanceof $team || $team instanceof $this;
97
98
        return $sameType && $this->color === $team->color;
0 ignored issues
show
Bug introduced by
Accessing color on the interface TeamInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
99
    }
100
}
101