Issues (11)

src/ReadModel/Match/OngoingMatches.php (1 issue)

1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\ReadModel\Match;
4
5
use Countable;
6
use Stratadox\CardGame\Match\MatchId;
7
use Stratadox\CardGame\Proposal\ProposalId;
8
use function count;
9
10
class OngoingMatches implements Countable
11
{
12
    /** @var OngoingMatch[] */
13
    private $matches = [];
14
15
    public function addFromProposal(ProposalId $proposal, OngoingMatch $match): void
16
    {
17
        $this->matches[$proposal->id()] = $match;
18
    }
19
20
    /** @throws NoSuchMatch */
21
    public function forProposal(ProposalId $proposal): OngoingMatch
22
    {
23
        if (!isset($this->matches[$proposal->id()])) {
24
            throw NoSuchMatch::forProposal($proposal);
25
        }
26
        return $this->matches[$proposal->id()];
27
    }
28
29
    public function withId(MatchId $id): OngoingMatch
30
    {
31
        foreach ($this->matches as $ongoingMatch) {
32
            if ($id->is($ongoingMatch->id())) {
33
                return $ongoingMatch;
34
            }
35
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Stratadox\CardGame\ReadModel\Match\OngoingMatch. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
36
        // @todo throw
37
    }
38
39
    public function count(): int
40
    {
41
        return count($this->matches);
42
    }
43
}
44