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