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

IndexProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndexes() 0 10 2
A __construct() 0 3 1
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