Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
11 | final class RecentNewsWasFound implements PolicyConditionInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var array<string,string> |
||
15 | * For example ['Symbol' => 'datetime'] |
||
16 | */ |
||
17 | private static array $cacheOldestBySymbol = []; |
||
18 | |||
19 | 3 | public function __invoke(Quote $quote): bool |
|
20 | { |
||
21 | 3 | if (null === $quote->getSymbol()) { |
|
22 | 2 | return false; |
|
23 | } |
||
24 | |||
25 | 2 | $current = $this->findLatestDateTimeFromNews($quote); |
|
26 | 2 | $previous = self::$cacheOldestBySymbol[$quote->getSymbol()] ?? ''; |
|
27 | |||
28 | 2 | self::$cacheOldestBySymbol[$quote->getSymbol()] = $current; |
|
29 | |||
30 | 2 | return $current > $previous; |
|
31 | } |
||
32 | |||
33 | 2 | private function findLatestDateTimeFromNews(Quote $quote): string |
|
49 | } |
||
50 | } |
||
51 |