TraitBitrixLoader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A sort() 0 4 1
A repositoryName() 0 7 2
A select() 0 4 1
A filter() 0 4 1
A setKey() 0 4 1
A getKey() 0 3 1
1
<?php
2
3
namespace Alex19pov31\LinkedData\Loaders;
4
5
trait TraitBitrixLoader
6
{
7
    /**
8
     * Список полей для выборки
9
     *
10
     * @var array
11
     */
12
    protected $select = [];
13
14
    /**
15
     * Порядок сортировки данных
16
     *
17
     * @var array
18
     */
19
    protected $sort = [];
20
21
    /**
22
     * Правила фильтрации данных
23
     *
24
     * @var array
25
     */
26
    protected $filter = [];
27
28
    /**
29
     * Имя репозитория
30
     *
31
     * @var string
32
     */
33
    protected $nameRepository;
34
35
    /**
36
     * Название поля используемое как ключ
37
     *
38
     * @var string
39
     */
40
    protected $key = 'ID';
41
42
    /**
43
     * Выборка полей
44
     *
45
     * @param array $select
46
     * @return TraitBitrixLoader
47
     */
48
    public function select(array $select): self
49
    {
50
        $this->select = $select;
51
        return $this;
52
    }
53
54
    public function setKey(string $key): self
55
    {
56
        $this->key = $key;
57
        return $this;
58
    }
59
60
    private function getKey(): string
61
    {
62
        return (string) $this->key;
63
    }
64
65
    /**
66
     * Сортировка данных
67
     * ["field"=>"asc|desc"]
68
     *
69
     * @param array $sort
70
     * @return TraitBitrixLoader
71
     */
72
    public function sort(array $sort): self
73
    {
74
        $this->sort = $sort;
75
        return $this;
76
    }
77
78
    /**
79
     * Фильтрация данных
80
     *
81
     * @param array $filter
82
     * @return TraitBitrixLoader
83
     */
84
    public function filter(array $filter): self
85
    {
86
        $this->filter = $filter;
87
        return $this;
88
    }
89
90
    private function repositoryName(string $key): string
91
    {
92
        if (!empty($this->nameRepository)) {
93
            return (string) $this->nameRepository;
94
        }
95
96
        return static::getRepositoryName($key);
97
    }
98
99
    abstract public static function getRepositoryName(string $key): string;
100
}
101