Lines 100.00% 8 / 8
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 attach 100.00% 7 / 7 100.00% 1 / 1 2
16final readonly class StartWithCurrentStateOperator implements StreamSource
17{
18    /** @param StreamSource<StateChange> $source */
19    public function __construct(
20        private StreamSource $source,
21        private CurrentStateReader $currentStates,
22    ) {}
23
24    public function attach(SubscriptionScope $scope, Closure $downstream): Subscription
25    {
26        $subscription = $this->source->attach($scope, $downstream);
27
28        foreach ($this->currentStates->readCurrentStates()->sortedByEntityId() as $state) {
29            $seed = StateChange::fromCurrentState($state);
30            $scope->emit(static function () use ($downstream, $seed): void {
31                $downstream($seed);
32            });
33        }
34
35        return $subscription;
36    }
37}