Passed
Push — master ( e0d6a2...2ec881 )
by Anton
05:25 queued 02:20
created

Count::__construct()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 6
nop 4
1
<?php
2
3
/**
4
 * @package Cadmium\Framework\DB
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace DB\Query {
11
12
	use DB;
13
14
	class Count extends DB\Query {
15
16
		/**
17
		 * Constructor
18
		 */
19
20
		public function __construct(string $table, string $column = '*', bool $distinct = false, $condition = null) {
21
22
			# Process arguments
23
24
			$table = $this->getName($table);
25
26
			if ($column !== '*') $column = (($distinct ? 'DISTINCT ' : '') . $this->getName($column));
27
28
			$condition = $this->getString($condition, '^name IN $list', ' AND ');
29
30
			# Build query
31
32
			$this->query = ('SELECT COUNT(' . $column . ') as count ' .
33
34
				'FROM ' . $table . ($condition ? (' WHERE (' .  $condition . ')') : ''));
35
		}
36
	}
37
}
38