Passed
Pull Request — master (#315)
by Sergei
27:15 queued 24:23
created

ArrayableTrait   A

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\BaseActiveRecord;
9
10
use function array_combine;
11
use function array_keys;
12
13
/**
14
 * Trait to implement {@see \Yiisoft\Arrays\ArrayableTrait} interface for ActiveRecord.
15
 *
16
 * @method string[] attributes()
17
 * @see BaseActiveRecord::attributes() for more info.
18
 *
19
 * @method array getRelatedRecords()
20
 * @see BaseActiveRecord::getRelatedRecords() for more info.
21
 */
22
trait ArrayableTrait
23
{
24
    use \Yiisoft\Arrays\ArrayableTrait;
25
26
    /**
27
     * @return array The default implementation returns the names of the relations that have been populated into this
28
     * record.
29
     */
30
    public function extraFields(): array
31
    {
32
        $fields = array_keys($this->getRelatedRecords());
33
34
        return array_combine($fields, $fields);
35
    }
36
37
    /**
38
     * @psalm-return array<string, string|Closure>
39
     */
40
    public function fields(): array
41
    {
42
        $fields = $this->attributes();
43
44
        return array_combine($fields, $fields);
45
    }
46
}
47