Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
FromEnum
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 support
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getIndexes
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\Core\Indexing;
3
4use Apie\Core\Context\ApieContext;
5use BackedEnum;
6use ReflectionClass;
7use UnitEnum;
8
9class FromEnum implements IndexingStrategyInterface
10{
11    public function support(object $object): bool
12    {
13        $refl = new ReflectionClass($object);
14        return $refl->isEnum();
15    }
16
17    /**
18     * @return array<string, int>
19     */
20    public function getIndexes(object $object, ApieContext $context, Indexer $indexer): array
21    {
22        assert($object instanceof UnitEnum);
23        if ($object instanceof BackedEnum) {
24            return [$object->name => 1, $object->value => 1];
25        }
26        return [$object->name => 1];
27    }
28}