Completed
Push — master ( 20edd5...7d7f4e )
by smiley
02:32
created

CreateTableAbstract::field()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 13
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Class CreateTableAbstract
4
 *
5
 * @filesource   CreateTableAbstract.php
6
 * @created      04.06.2017
7
 * @package      chillerlan\Database\Query\Dialects
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Database\Query;
14
15
abstract class CreateTableAbstract extends StatementAbstract implements CreateTableInterface{
16
17
	/**
18
	 * @var string
19
	 */
20
	protected $name;
21
22
	/**
23
	 * @var bool
24
	 */
25
	protected $ifNotExists = false;
26
27
	/**
28
	 * @var bool
29
	 */
30
	protected $temp = false;
31
32
	/**
33
	 * @var string
34
	 */
35
	protected $primaryKey;
36
37
	/**
38
	 * @var array
39
	 */
40
	protected $cols = [];
41
42
	/**
43
	 * @var string
44
	 */
45
	protected $collate;
46
47
	/**
48
	 * @param string $collation
49
	 *
50
	 * @return \chillerlan\Database\Query\CreateTableInterface
51
	 */
52
	public function charset(string $collation):CreateTableInterface{
53
		$collation = trim($collation);
54
55
		if(!empty($collation)){
56
			$this->collate = $collation;
57
		}
58
59
		return $this;
60
	}
61
62
	/**
63
	 * @return \chillerlan\Database\Query\CreateTableInterface
64
	 */
65
	public function temp():CreateTableInterface{
66
		$this->temp = true;
67
68
		return $this;
69
	}
70
71
	/**
72
	 * @return \chillerlan\Database\Query\CreateTableInterface
73
	 */
74
	public function ifNotExists():CreateTableInterface{
75
		$this->ifNotExists = true;
76
77
		return $this;
78
	}
79
80
	/**
81
	 * @param string|null $tablename
82
	 *
83
	 * @return \chillerlan\Database\Query\CreateTableInterface
84
	 */
85
	public function name(string $tablename = null):CreateTableInterface{
86
		$name = trim($tablename);
87
88
		if(!empty($name)){
89
			$this->name = $tablename;
90
		}
91
92
		return $this;
93
	}
94
95
	/**
96
	 * @param string $field
97
	 *
98
	 * @return \chillerlan\Database\Query\CreateTableInterface
99
	 */
100
	public function primaryKey(string $field):CreateTableInterface{
101
		$this->primaryKey = $field;
102
103
		return $this;
104
	}
105
106
	/**
107
	 * @param string      $name
108
	 * @param string      $type
109
	 * @param null        $length
110
	 * @param string|null $attribute
111
	 * @param string|null $collation
112
	 * @param bool|null   $isNull
113
	 * @param string|null $defaultType
114
	 * @param null        $defaultValue
115
	 * @param string|null $extra
116
	 *
117
	 * @return mixed
118
	 */
119
	abstract protected function fieldspec(
120
		string $name,
121
		string $type,
122
		$length = null,
123
		string $attribute = null,
124
		string $collation = null,
125
		bool $isNull = null,
126
		string $defaultType = null,
127
		$defaultValue = null,
128
		string $extra = null
129
	);
130
131
	/**
132
	 * @param string      $name
133
	 * @param string      $type
134
	 * @param null        $length
135
	 * @param string|null $attribute
136
	 * @param string|null $collation
137
	 * @param bool|null   $isNull
138
	 * @param string|null $defaultType
139
	 * @param null        $defaultValue
140
	 * @param string|null $extra
141
	 *
142
	 * @return \chillerlan\Database\Query\CreateTableInterface
143
	 */
144
	public function field(
145
		string $name,
146
		string $type,
147
		$length = null,
148
		string $attribute = null,
149
		string $collation = null,
150
		bool $isNull = null,
151
		string $defaultType = null,
152
		$defaultValue = null,
153
		string $extra = null
154
	):CreateTableInterface {
155
156
		$this->cols[$name] = $this->fieldspec($name, $type, $length, $attribute, $collation, $isNull, $defaultType, $defaultValue, $extra);
157
158
		return $this;
159
	}
160
161
	/**
162
	 * @param $name
163
	 *
164
	 * @return \chillerlan\Database\Query\CreateTableInterface
165
	 */
166
#	public function index($name):CreateTableInterface{}
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
167
168
}
169