Completed
Push — 6.0 ( be0b6e...c47dd5 )
by liu
06:54 queued 10s
created

TableFieldInfo   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 91
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldType() 0 5 1
A getFields() 0 3 2
A setFieldType() 0 4 1
A getTableFields() 0 7 2
A getFieldBindType() 0 5 2
A getFieldsType() 0 7 2
A getFieldsBindType() 0 5 1
1
<?php
2
// +----------------------------------------------------------------------
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\db\concern;
14
15
/**
16
 * 数据字段信息
17
 */
18
trait TableFieldInfo
19
{
20
21
    /**
22
     * 获取数据表字段信息
23
     * @access public
24
     * @param string $tableName 数据表名
25
     * @return array
26
     */
27
    public function getTableFields($tableName = ''): array
28
    {
29
        if ('' == $tableName) {
30
            $tableName = $this->getTable();
0 ignored issues
show
Bug introduced by
The method getTable() does not exist on think\db\concern\TableFieldInfo. Did you maybe mean getTableFields()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            /** @scrutinizer ignore-call */ 
31
            $tableName = $this->getTable();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
        }
32
33
        return $this->connection->getTableFields($tableName);
34
    }
35
36
    /**
37
     * 设置字段类型信息
38
     * @access public
39
     * @param array $type 字段类型信息
40
     * @return $this
41
     */
42
    public function setFieldType(array $type)
43
    {
44
        $this->options['field_type'] = $type;
0 ignored issues
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
        return $this;
46
    }
47
48
    /**
49
     * 获取详细字段类型信息
50
     * @access public
51
     * @param string $tableName 数据表名称
52
     * @return array
53
     */
54
    public function getFields(string $tableName = ''): array
55
    {
56
        return $this->connection->getFields($tableName ?: $this->getTable());
57
    }
58
59
    /**
60
     * 获取字段类型信息
61
     * @access public
62
     * @return array
63
     */
64
    public function getFieldsType(): array
65
    {
66
        if (!empty($this->options['field_type'])) {
67
            return $this->options['field_type'];
68
        }
69
70
        return $this->connection->getFieldsType($this->getTable());
71
    }
72
73
    /**
74
     * 获取字段类型信息
75
     * @access public
76
     * @param string $field 字段名
77
     * @return string|null
78
     */
79
    public function getFieldType(string $field)
80
    {
81
        $fieldType = $this->getFieldsType();
82
83
        return $fieldType[$field] ?? null;
84
    }
85
86
    /**
87
     * 获取字段类型信息
88
     * @access public
89
     * @return array
90
     */
91
    public function getFieldsBindType(): array
92
    {
93
        $fieldType = $this->getFieldsType();
94
95
        return array_map([$this->connection, 'getFieldBindType'], $fieldType);
96
    }
97
98
    /**
99
     * 获取字段类型信息
100
     * @access public
101
     * @param string $field 字段名
102
     * @return int
103
     */
104
    public function getFieldBindType(string $field): int
105
    {
106
        $fieldType = $this->getFieldType($field);
107
108
        return $this->connection->getFieldBindType($fieldType ?: '');
109
    }
110
111
}
112