Lines 100.00% 5 / 5
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
EntityIdLiterals 100.00% 5 / 5 100.00% 1 / 1 3 100.00% 1 / 1
 listEntityIds 100.00% 5 / 5 100.00% 1 / 1 3
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\PHPStan\Rule;
6
7use PHPStan\Type\Type;
8use Stewart\Contracts\Entity\EntityId;
9
10final readonly class EntityIdLiterals
11{
12    // Globs, times of day and other strings that are no entity ID are left alone.
13    /** @return list<string> */
14    public function listEntityIds(Type $type): array
15    {
16        $entityIds = [];
17
18        foreach ($type->getConstantStrings() as $string) {
19            if (EntityId::tryFromString($string->getValue()) !== null) {
20                $entityIds[] = $string->getValue();
21            }
22        }
23
24        return $entityIds;
25    }
26}