Completed
Push — master ( 47c098...6c95d6 )
by smiley
02:23
created

CreateTableAbstract::field()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
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
use chillerlan\Database\Query\Traits\IfNotExistsTrait;
16
use chillerlan\Database\Query\Traits\NameTrait;
17
18
abstract class CreateTableAbstract extends StatementAbstract implements CreateTableInterface{
19
	use IfNotExistsTrait, NameTrait;
20
21
	protected $temp = false;
22
	protected $primaryKey;
23
	protected $cols = [];
24
25
	public function ifNotExists():CreateTableInterface{return $this->_ifNotExists();}
26
	public function name(string $dbname = null):CreateTableInterface{return $this->_name($dbname);}
27
28
	public function execute(){
29
		// TODO: Implement execute() method.
30
	}
31
32
	public function temp():CreateTableInterface{
33
		$this->temp = true;
34
35
		return $this;
36
	}
37
38
	public function primaryKey(string $field):CreateTableInterface{
39
		$this->primaryKey = $field;
40
41
		return $this;
42
	}
43
44
	abstract protected function fieldspec(
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
45
		string $name,
46
		string $type,
47
		$length = null,
48
		string $attribute = null,
49
		string $collation = null,
50
		bool $isNull = false,
51
		string $defaultType = null,
52
		$defaultValue = null,
53
		string $extra = null
54
	);
55
56
	public function field(
57
		string $name,
58
		string $type,
59
		$length = null,
60
		string $attribute = null,
61
		string $collation = null,
62
		bool $isNull = false,
63
		string $defaultType = null,
64
		$defaultValue = null,
65
		string $extra = null
66
	):CreateTableInterface {
67
68
		$this->cols[$name] = $this->fieldspec(
69
			$name,
70
			$type,
71
			$length,
72
			$attribute,
73
			$collation,
74
			$isNull,
75
			$defaultType,
76
			$defaultValue,
77
			$extra
78
		);
79
80
		return $this;
81
	}
82
83
	public function index($name){
84
		// TODO: Implement index() method.
85
	}
86
}
87