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

ArrayableTrait::extraFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
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