Passed
Push — master ( 3ec735...0b5e67 )
by Chema
01:36 queued 14s
created

NotifyResult::conditionNamesGroupBySymbol()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTicker\Domain\Notifier;
6
7
use Chemaclass\StockTicker\Domain\ReadModel\Company;
8
9
final class NotifyResult
10
{
11
    /** @psalm-var array<string, array{company: Company, conditionNames: string[]}> */
12
    private array $result = [];
13
14
    /**
15
     * @param string[] $conditionNames
16
     */
17 4
    public function add(Company $company, array $conditionNames): self
18
    {
19 4
        $this->result[$company->symbol()->toString()] = [
20 4
            'company' => $company,
21 4
            'conditionNames' => $conditionNames,
22
        ];
23
24 4
        return $this;
25
    }
26
27
    /**
28
     * @return string[]
29
     */
30 3
    public function symbols(): array
31
    {
32 3
        return array_keys($this->result);
33
    }
34
35
    /**
36
     * @return string[]
37
     */
38 2
    public function conditionNamesForSymbol(string $symbol): array
39
    {
40 2
        return $this->result[$symbol]['conditionNames'];
41
    }
42
43 1
    public function conditionNamesGroupBySymbol(): array
44
    {
45 1
        $conditionNamesBySymbol = [];
46
47 1
        foreach ($this->symbols() as $symbol) {
48 1
            $conditionNamesBySymbol[$symbol] = $this->conditionNamesForSymbol($symbol);
49
        }
50
51 1
        return $conditionNamesBySymbol;
52
    }
53
54 1
    public function companyForSymbol(string $symbol): Company
55
    {
56 1
        return $this->result[$symbol]['company'] ?? Company::empty();
57
    }
58
59 1
    public function isEmpty(): bool
60
    {
61 1
        return empty($this->result);
62
    }
63
}
64