Completed
Push — master ( ec27e4...948d8b )
by smiley
14:17
created

CreateTableAbstract::fieldspec()

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
nc 1
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
	protected $name;
18
	protected $ifNotExists = false;
19
	protected $temp = false;
20
	protected $primaryKey;
21
	protected $cols = [];
22
23
	protected $collate;
24
25 View Code Duplication
	public function charset(string $collation):CreateTableInterface{
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
		$collation = trim($collation);
27
28
		if(!empty($collation)){
29
			$this->collate = $collation;
30
		}
31
32
		return $this;
33
	}
34
35
	public function temp():CreateTableInterface{
36
		$this->temp = true;
37
38
		return $this;
39
	}
40
41
	public function ifNotExists():CreateTableInterface{
42
		$this->ifNotExists = true;
43
44
		return $this;
45
	}
46
47
	public function name(string $tablename = null):CreateTableInterface{
48
		$name = trim($tablename);
49
50
		if(!empty($name)){
51
			$this->name = $tablename;
52
		}
53
54
		return $this;
55
	}
56
57
	public function primaryKey(string $field):CreateTableInterface{
58
		$this->primaryKey = $field;
59
60
		return $this;
61
	}
62
63
	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...
64
		string $name,
65
		string $type,
66
		$length = null,
67
		string $attribute = null,
68
		string $collation = null,
69
		bool $isNull = false,
70
		string $defaultType = null,
71
		$defaultValue = null,
72
		string $extra = null
73
	);
74
75
	public function field(
76
		string $name,
77
		string $type,
78
		$length = null,
79
		string $attribute = null,
80
		string $collation = null,
81
		bool $isNull = false,
82
		string $defaultType = null,
83
		$defaultValue = null,
84
		string $extra = null
85
	):CreateTableInterface {
86
87
		$this->cols[$name] = $this->fieldspec($name, $type, $length, $attribute, $collation, $isNull, $defaultType, $defaultValue, $extra);
88
89
		return $this;
90
	}
91
92
	public function index($name){
93
		// TODO: Implement index() method.
94
	}
95
}
96