NotifyResult::conditionNamesForSymbol()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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