OngoingMatches   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addFromProposal() 0 3 1
A count() 0 3 1
A withId() 0 5 3
A forProposal() 0 6 2
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