Lines 100.00% 9 / 9
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 selectEntities 100.00% 8 / 8 100.00% 1 / 1 4
 isHiddenAway 100.00% 1 / 1 100.00% 1 / 1 3
12final readonly class EntitySelector
13{
14    public function selectEntities(Snapshot $snapshot, EntityInclusionRules $inclusionRules): EntitySelection
15    {
16        $generated = [];
17        $ignored = [];
18
19        foreach ($snapshot->states as $state) {
20            if ($this->isHiddenAway($snapshot->registry->find($state->entityId)) || !$inclusionRules->allows($state->entityId)) {
21                $ignored[] = $state->entityId;
22
23                continue;
24            }
25
26            $generated[] = $state;
27        }
28
29        return new EntitySelection(EntityStateCollection::keyedByEntityId($generated), EntityIdCollection::fromList($ignored));
30    }
31
32    private function isHiddenAway(?EntityRegistryEntry $entry): bool
33    {
34        return $entry !== null && ($entry->isDisabled() || $entry->isHidden());
35    }
36}