Lines 100.00% 5 / 5
Functions and Methods 100.00% 5 / 5
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
CrossingLatches 100.00% 5 / 5 100.00% 5 / 5 5 100.00% 1 / 1
 isKnown 100.00% 1 / 1 100.00% 1 / 1 1
 isFired 100.00% 1 / 1 100.00% 1 / 1 1
 recordArmed 100.00% 1 / 1 100.00% 1 / 1 1
 recordFired 100.00% 1 / 1 100.00% 1 / 1 1
 forget 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Support\Stream;
6
7/** @internal */
8final class CrossingLatches
9{
10    /** @var array<string, bool> */
11    private array $firedByKey = [];
12
13    public function isKnown(string $key): bool
14    {
15        return \array_key_exists($key, $this->firedByKey);
16    }
17
18    public function isFired(string $key): bool
19    {
20        return $this->firedByKey[$key] ?? false;
21    }
22
23    public function recordArmed(string $key): void
24    {
25        $this->firedByKey[$key] = false;
26    }
27
28    public function recordFired(string $key): void
29    {
30        $this->firedByKey[$key] = true;
31    }
32
33    public function forget(string $key): void
34    {
35        unset($this->firedByKey[$key]);
36    }
37}