CustomerForArrayable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 20
dl 0
loc 46
rs 10
c 1
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fields() 0 8 1
A getTableName() 0 3 1
A toArray() 0 7 2
A setItems() 0 3 1
A setItem() 0 3 1
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