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

NotifyResult   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 53
rs 10
ccs 18
cts 18
cp 1
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 8 1
A conditionNamesGroupBySymbol() 0 9 2
A companyForSymbol() 0 3 1
A conditionNamesForSymbol() 0 3 1
A isEmpty() 0 3 1
A symbols() 0 3 1
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