Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

TPrimaryKey   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrimaryKeys() 0 3 1
A addPrimaryKey() 0 3 1
A filterPrimary() 0 3 2
1
<?php
2
3
namespace kalanis\kw_mapper\Mappers\Shared;
4
5
6
/**
7
 * Trait TPrimaryKey
8
 * @package kalanis\kw_mapper\Mappers\Shared
9
 * Simple work with primary keys
10
 * There can be multiple of them as combined PKs
11
 */
12
trait TPrimaryKey
13
{
14
    /** @var string[] */
15
    protected $primaryKeys = [];
16
17 40
    public function addPrimaryKey(string $localAlias): void
18
    {
19 40
        $this->primaryKeys[] = $localAlias;
20
    }
21
22
    /**
23
     * @return string[]
24
     */
25 15
    public function getPrimaryKeys(): array
26
    {
27 15
        return $this->primaryKeys;
28
    }
29
30
    /**
31
     * @param mixed $v
32
     * @param string|int $k
33
     * @return bool
34
     */
35 1
    public function filterPrimary($v, $k): bool
36
    {
37 1
        return in_array($k, $this->primaryKeys) && !empty($v);
38
    }
39
}
40