Passed
Push — master ( bc8b6f...7a9b1f )
by Sergei
02:57
created

CustomerForArrayable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 38
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setItem() 0 3 1
A fields() 0 8 1
A setItems() 0 3 1
A getTableName() 0 3 1
A toArray() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord;
6
7
use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord;
8
9
/**
10
 * Class CustomerClosureField.
11
 *
12
 * @property int $id
13
 * @property string $name
14
 * @property string $email
15
 * @property string $address
16
 * @property int $status
17
 */
18
class CustomerForArrayable extends MagicActiveRecord
19
{
20
    public array $items = [];
21
22
    public ?CustomerForArrayable $item = null;
23
24
    public function getTableName(): string
25
    {
26
        return 'customer';
27
    }
28
29
    public function fields(): array
30
    {
31
        $fields = parent::fields();
32
33
        $fields['item'] = 'item';
34
        $fields['items'] = 'items';
35
36
        return $fields;
37
    }
38
39
    public function setItem(self $item)
40
    {
41
        $this->item = $item;
42
    }
43
44
    public function setItems(self ...$items)
45
    {
46
        $this->items = $items;
47
    }
48
49
    public function toArray(array $fields = [], array $expand = [], bool $recursive = true): array
50
    {
51
        $data = parent::toArray($fields, $expand, $recursive);
52
53
        $data['status'] = $this->status == 1 ? 'active' : 'inactive';
54
55
        return $data;
56
    }
57
}
58