Completed
Push — master ( 8fe4e7...fafc98 )
by Dan
23:10
created

Player::equals()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 5
nop 1
crap 5
1
<?php
2
3
namespace Cysha\Casino\Holdem\Game;
4
5
use Assert\Assertion;
6
use Cysha\Casino\Game\Chips;
7
use Cysha\Casino\Game\Client;
8
use Cysha\Casino\Game\Contracts\Player as PlayerContract;
9
use Ramsey\Uuid\Uuid;
10
11
class Player extends Client implements PlayerContract
12
{
13
    /**
14
     * @var Chips
15
     */
16
    private $chipStack;
17
18
    /**
19
     * PlayerTest constructor.
20
     *
21
     * @param string $name
22
     * @param Chips  $chips
23 145
     */
24
    public function __construct(Uuid $id, $name, Chips $wallet = null, Chips $chips = null)
25 145
    {
26
        parent::__construct($id, $name, $wallet);
27 145
28 145
        $this->chipStack = $chips ?? Chips::zero();
29
    }
30
31
    /**
32
     * @param Client $client
33
     * @param Chips  $chipCount
34
     *
35
     * @return PlayerContract
36 145
     */
37
    public static function fromClient(Client $client, Chips $chipCount = null): PlayerContract
38 145
    {
39
        return new self($client->id(), $client->name(), $client->wallet(), $chipCount);
40
    }
41
42
    /**
43
     * @param PlayerContract $object
44
     *
45
     * @return bool
46 27
     */
47
    public function equals(PlayerContract $object): bool
48 27
    {
49 27
        return static::class === get_class($object)
50 27
        && $this->id() === $object->id()
51 27
        && $this->name() === $object->name()
52
        && $this->wallet() === $object->wallet()
53
        && $this->chipStack() === $object->chipStack();
54
    }
55
56
    /**
57 45
     * @return Chips
58
     */
59 45
    public function chipStack(): Chips
60
    {
61
        return $this->chipStack;
62
    }
63
64
    /**
65 32
     * @param Chips $chips
66
     */
67 32
    public function bet(Chips $chips)
68 31
    {
69 31
        Assertion::greaterOrEqualThan($chips->amount(), 0);
70
        $this->chipStack()->subtract($chips);
71
    }
72
}
73