Total Complexity | 7 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
10 | class OngoingMatches implements Countable |
||
11 | { |
||
12 | /** @var OngoingMatch[] */ |
||
13 | private $matches = []; |
||
14 | |||
15 | public function addFromProposal(ProposalId $proposal, OngoingMatch $match): void |
||
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 | } |
||
|
|||
36 | // @todo throw |
||
37 | } |
||
38 | |||
39 | public function count(): int |
||
42 | } |
||
43 | } |
||
44 |
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: