Completed
Push — master ( ffbb02...68e5b2 )
by smiley
02:42
created

CreateDatabase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 27
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B sql() 0 21 5
1
<?php
2
/**
3
 * Class CreateDatabase
4
 *
5
 * @filesource   CreateDatabase.php
6
 * @created      12.06.2017
7
 * @package      chillerlan\Database\Query\Dialects\MySQL
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Database\Query\Dialects\MySQL;
14
15
use chillerlan\Database\Query\{CreateDatabaseAbstract, QueryException};
16
17
class CreateDatabase extends CreateDatabaseAbstract{
18
19
	protected $collate = 'utf8mb4_bin';
20
21
	public function sql():string{
22
23
		if(empty($this->name)){
24
			throw new QueryException('no name specified');
25
		}
26
27
		list($charset) = explode('_', $this->collate);
28
29
		$collate = 'CHARACTER SET '.$charset;
30
31
		if($charset !== $this->collate){
32
			$collate .= ' COLLATE '.$this->collate;
33
		}
34
35
		$sql = 'CREATE DATABASE ';
36
		$sql .= $this->ifNotExists ? 'IF NOT EXISTS ' : '';
37
		$sql .= $this->quote($this->name);
38
		$sql .= $this->collate ? ' '.$collate : '';
39
40
		return $sql;
41
	}
42
43
}
44