Completed
Push — master ( 4b1e3c...30d3d2 )
by Jesse
02:57
created

Block::as()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Match\Command;
4
5
use Stratadox\CardGame\Match\Command\BlockTheAttacker;
6
use Stratadox\CardGame\Match\MatchId;
7
8
final class Block
9
{
10
    /** @var int */
11
    private $attacker;
12
    /** @var int|null */
13
    private $defender;
14
    /** @var int|null */
15
    private $player;
16
    /** @var MatchId|null */
17
    private $match;
18
19
    public function __construct(
20
        int $attacker,
21
        ?int $defender,
22
        ?int $player,
23
        ?MatchId $match
24
    ) {
25
        $this->attacker = $attacker;
26
        $this->defender = $defender;
27
        $this->player = $player;
28
        $this->match = $match;
29
    }
30
31
    public static function attacker(int $attacker): self
32
    {
33
        return new self($attacker, null, null, null);
34
    }
35
36
    public function withDefender(int $defender): self
37
    {
38
        return new self($this->attacker, $defender, $this->player, $this->match);
39
    }
40
41
    public function as(int $player): self
42
    {
43
        return new self($this->attacker, $this->defender, $player, $this->match);
44
    }
45
46
    public function in(MatchId $match): self
47
    {
48
        return new self($this->attacker, $this->defender, $this->player, $match);
49
    }
50
51
    public function go(): BlockTheAttacker
52
    {
53
        return BlockTheAttacker::number(
54
            $this->attacker,
55
            $this->defender,
0 ignored issues
show
Bug introduced by
It seems like $this->defender can also be of type null; however, parameter $defender of Stratadox\CardGame\Match...ckTheAttacker::number() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
            /** @scrutinizer ignore-type */ $this->defender,
Loading history...
56
            $this->player,
0 ignored issues
show
Bug introduced by
It seems like $this->player can also be of type null; however, parameter $player of Stratadox\CardGame\Match...ckTheAttacker::number() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
            /** @scrutinizer ignore-type */ $this->player,
Loading history...
57
            $this->match
0 ignored issues
show
Bug introduced by
It seems like $this->match can also be of type null; however, parameter $match of Stratadox\CardGame\Match...ckTheAttacker::number() does only seem to accept Stratadox\CardGame\Match\MatchId, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            /** @scrutinizer ignore-type */ $this->match
Loading history...
58
        );
59
    }
60
}
61