Passed
Pull Request — master (#315)
by Sergei
16:31 queued 13:33
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 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