Passed
Push — 2.x ( 5e81a5...d097d1 )
by Aleksei
14:17
created

IndexProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Service\Implementation;
6
7
use Cycle\ORM\Service\IndexProviderInterface;
8
use Cycle\ORM\SchemaInterface;
9
10
use const SORT_REGULAR;
11
12
/**
13
 * @internal
14
 */
15
final class IndexProvider implements IndexProviderInterface
16
{
17
    private array $indexes = [];
18
19 7418
    public function __construct(
20
        private SchemaInterface $schema,
21
    ) {
22
    }
23
24 5308
    public function getIndexes(string $entity): array
25
    {
26 5308
        if (isset($this->indexes[$entity])) {
27 3918
            return $this->indexes[$entity];
28
        }
29
30 5308
        $pk = $this->schema->define($entity, SchemaInterface::PRIMARY_KEY);
31 5308
        $keys = $this->schema->define($entity, SchemaInterface::FIND_BY_KEYS) ?? [];
32
33 5308
        return $this->indexes[$entity] = \array_unique(\array_merge([$pk], $keys), SORT_REGULAR);
34
    }
35
}
36