ArrayableTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fields() 0 5 1
A extraFields() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Trait;
6
7
use Closure;
8
use Yiisoft\ActiveRecord\AbstractActiveRecord;
9
use Yiisoft\ActiveRecord\ActiveRecordInterface;
10
11
use function array_combine;
12
use function array_keys;
13
14
/**
15
 * Trait to implement {@see \Yiisoft\Arrays\ArrayableTrait} interface for ActiveRecord.
16
 *
17
 * @method string[] attributes()
18
 * @see ActiveRecordInterface::attributes()
19
 *
20
 * @method array getRelatedRecords()
21
 * @see AbstractActiveRecord::getRelatedRecords()
22
 */
23
trait ArrayableTrait
24
{
25
    use \Yiisoft\Arrays\ArrayableTrait;
26
27
    /**
28
     * @return array The default implementation returns the names of the relations that have been populated into this
29
     * record.
30
     */
31
    public function extraFields(): array
32
    {
33
        $fields = array_keys($this->getRelatedRecords());
34
35
        return array_combine($fields, $fields);
36
    }
37
38
    /**
39
     * @psalm-return array<string, string|Closure>
40
     */
41
    public function fields(): array
42
    {
43
        $fields = $this->attributes();
44
45
        return array_combine($fields, $fields);
46
    }
47
}
48