Completed
Push — master ( d508c6...ead087 )
by smiley
02:37
created

Select::sql()   C

Complexity

Conditions 8
Paths 65

Size

Total Lines 22
Code Lines 14

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
c 0
b 0
f 0
rs 6.6037
cc 8
eloc 14
nc 65
nop 0
1
<?php
2
/**
3
 * Class Select
4
 *
5
 * @filesource   Select.php
6
 * @created      03.06.2017
7
 * @package      chillerlan\Database\Query\Dialects\Postgres
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Database\Query\Dialects\Postgres;
14
15
use chillerlan\Database\Query\QueryException;
16
use chillerlan\Database\Query\SelectAbstract;
17
18
/**
19
 * @link https://www.postgresql.org/docs/current/static/sql-select.html
20
 */
21 View Code Duplication
class Select extends SelectAbstract{
0 ignored issues
show
Duplication introduced by
This class 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...
22
23
	/**
24
	 * @return string
25
	 * @throws \chillerlan\Database\Query\QueryException
26
	 */
27
	public function sql():string{
28
29
		if(empty($this->from)){
30
			throw new QueryException('no FROM expression specified');
31
		}
32
33
#		print_r([$this->cols, $this->from, $this->orderby, $this->groupby, $this->where]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
34
35
		$glue = ','.PHP_EOL."\t";
36
37
		$sql  = 'SELECT ';
38
		$sql .= $this->distinct ? 'DISTINCT ' : '';
39
		$sql .= !empty($this->cols) ? implode($glue , $this->cols).PHP_EOL : '* ';
40
		$sql .= 'FROM '.implode($glue , $this->from);
41
		$sql .= $this->_getWhere();
42
		$sql .= !empty($this->groupby) ? PHP_EOL.'GROUP BY '.implode($glue, $this->groupby) : '';
43
		$sql .= !empty($this->orderby) ? PHP_EOL.'ORDER BY '.implode($glue, $this->orderby) : '';
44
		$sql .= $this->offset ? PHP_EOL.'OFFSET ?' : '';
45
		$sql .= $this->limit ? PHP_EOL.'LIMIT ?' : '';
46
47
		return $sql;
48
	}
49
50
51
}
52