Lines 100.00% 4 / 4
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
CachedStateReader 100.00% 4 / 4 100.00% 2 / 2 3 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 readCurrentStates 100.00% 3 / 3 100.00% 1 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\State;
6
7use Stewart\Contracts\Registry\EntityFilter;
8use Stewart\Contracts\Selector\Selector;
9use Stewart\Contracts\State\Collection\EntityStateCollection;
10use Stewart\Runtime\Registry\RegistryCache;
11use Stewart\Support\State\CurrentStateReader;
12
13final readonly class CachedStateReader implements CurrentStateReader
14{
15    public function __construct(
16        private StateCache $states,
17        private RegistryCache $registry,
18        private Selector|EntityFilter $match,
19    ) {}
20
21    public function readCurrentStates(): EntityStateCollection
22    {
23        return $this->match instanceof EntityFilter
24            ? $this->states->getAllStates()->filterByEntityFilter($this->match, $this->registry)
25            : $this->states->filterBySelector($this->match);
26    }
27}