CompanySeeder::convertChildren()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
c 1
b 1
f 0
dl 0
loc 10
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Database\Seeders;
4
5
use Illuminate\Database\Seeder;
6
use SimpleCMS\Framework\Models\Dict;
7
8
class CompanySeeder extends Seeder
9
{
10
    /**
11
     * Run the database seeds.
12
     */
13
    public function run(): void
14
    {
15
        $data = $this->getList();
16
        foreach ($data as $sql) {
17
            if (!Dict::where('code', $sql['code'])->first()) {
18
                $this->addDict($sql);
19
            }
20
        }
21
    }
22
23
    private function addDict($data): void
24
    {
25
        $dict = Dict::create(['name' => $data['name'], 'code' => $data['code']]);
26
        $dict->items()->createMany($this->convertChildren($data['children']));
27
28
    }
29
30
    private function convertChildren(array $data): array
31
    {
32
        $result = [];
33
        foreach ($data as $value => $name) {
34
            $result[] = [
35
                'name' => $name,
36
                'content' => $value
37
            ];
38
        }
39
        return $result;
40
    }
41
42
    private function getList()
43
    {
44
        return [
45
            [
46
                'name' => '企业状态',
47
                'code' => 'company_status',
48
                'children' => ['营业中', '歇业', '闭业', '清退']
49
            ],
50
            [
51
                'name' => '企业申请状态',
52
                'code' => 'company_apply_status',
53
                'children' => ['待提交', '审核中', '审核通过', '审核拒绝', '关闭']
54
            ],
55
            [
56
                'name' => '企业日志请求类型',
57
                'code' => 'company_log_method',
58
                'children' => ['OPTION', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE']
59
            ],
60
            [
61
                'name' => '企业等级标识',
62
                'code' => 'company_level',
63
                'children' => ['Lv.0', 'Lv.1', 'Lv.2', 'Lv.3', 'Lv.4', 'Lv.5']
64
            ],
65
        ];
66
    }
67
}
68