Extractor::getFieldNames()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Pgs\ElasticOM;
4
5
use Pgs\ElasticOM\Annotation\ClassMetadata;
6
use Pgs\ElasticOM\Annotation\Id;
7
8
class Extractor
9
{
10 3
    public function getIdName(string $entityClass): string
11
    {
12 3
        $ids = array_keys(array_filter(
13 3
            ClassMetadata::getRawConfig($entityClass),
14 3
            function (array $values) {
15 3
                return !empty($values[Id::KEY_NAME]);
16 3
            }
17
        ));
18
19 3
        if (count($ids) !== 1) {
20 2
            throw new Exception(sprintf(
21 2
                'No or more than one identifier specified for entity "%s". Every entity must have one identifier',
22
                $entityClass
23
            ));
24
        }
25
26 1
        return reset($ids);
27
    }
28
29 1
    public function getFieldNames(string $entityClass): array
30
    {
31 1
        return array_keys(ClassMetadata::getRawConfig($entityClass));
32
    }
33
}
34