| Total Complexity | 5 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | final class OlderWasFound implements PolicyConditionInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var array<string,string> |
||
| 14 | * For example ['TickerSymbol' => 'datetime'] |
||
| 15 | */ |
||
| 16 | private static array $cacheOldestBySymbol = []; |
||
| 17 | |||
| 18 | private string $companyKey; |
||
| 19 | |||
| 20 | private string $keyToCompare; |
||
| 21 | |||
| 22 | 1 | public function __construct(string $companyKey, string $keyToCompare = 'datetime') |
|
| 23 | { |
||
| 24 | 1 | $this->companyKey = $companyKey; |
|
| 25 | 1 | $this->keyToCompare = $keyToCompare; |
|
| 26 | 1 | } |
|
| 27 | |||
| 28 | 1 | public function __invoke(Company $company): bool |
|
| 29 | { |
||
| 30 | 1 | $current = $this->findLatestDateTimeFromNews($company); |
|
| 31 | 1 | $previous = self::$cacheOldestBySymbol[$company->symbol()->toString()] ?? ''; |
|
| 32 | |||
| 33 | 1 | self::$cacheOldestBySymbol[$company->symbol()->toString()] = $current; |
|
| 34 | |||
| 35 | 1 | return $current > $previous; |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | private function findLatestDateTimeFromNews(Company $company): string |
|
| 54 | } |
||
| 55 | } |
||
| 56 |