CustomerForArrayable::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 7
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
6
7
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
8
9
/**
10
 * Class CustomerClosureField.
11
 */
12
class CustomerForArrayable extends ActiveRecord
13
{
14
    public array $items = [];
15
16
    public ?CustomerForArrayable $item = null;
17
18
    protected int $id;
19
    protected string $email;
20
    protected string|null $name = null;
21
    protected string|null $address = null;
22
    protected int|null $status = 0;
23
    protected bool|string|null $bool_status = false;
24
    protected int|null $profile_id = null;
25
26
    public function getTableName(): string
27
    {
28
        return 'customer';
29
    }
30
31
    public function fields(): array
32
    {
33
        $fields = parent::fields();
34
35
        $fields['item'] = 'item';
36
        $fields['items'] = 'items';
37
38
        return $fields;
39
    }
40
41
    public function setItem(self $item)
42
    {
43
        $this->item = $item;
44
    }
45
46
    public function setItems(self ...$items)
47
    {
48
        $this->items = $items;
49
    }
50
51
    public function toArray(array $fields = [], array $expand = [], bool $recursive = true): array
52
    {
53
        $data = parent::toArray($fields, $expand, $recursive);
54
55
        $data['status'] = $this->status == 1 ? 'active' : 'inactive';
56
57
        return $data;
58
    }
59
}
60