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

CreateDatabase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

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