ResultsModel::getResults()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 9

Duplication

Lines 23
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 23
loc 23
rs 9.0856
cc 3
eloc 9
nc 2
nop 0
1
<?php
2
namespace Kineo\Model;
3
4
use Kineo\Component\Database;
5
6 View Code Duplication
class ResultsModel extends BaseModel 
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...
7
{
8
	protected $db;
9
	
10
	public $results = array();
11
	
12
	public function __construct(Database $db)
13
	{
14
		$this->db = $db;
15
	}
16
	
17
	public function getResults() 
18
	{
19
		$stmt = $this->db->query(
20
			"SELECT a.name, a.party, a.constituency_id, c.name AS constituency, COUNT(*) AS count 
21
			FROM tblCandidates AS a
22
			INNER JOIN tblVotes AS b
23
			ON a.id = b.candidate_id
24
			LEFT JOIN tblConstituencies AS c
25
			ON a.constituency_id = c.id
26
			GROUP BY b.candidate_id
27
			ORDER BY count DESC, constituency ASC"
28
		);
29
		
30
		$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
31
		
32
		if(is_array($result) && !empty($result)) {
33
			$this->results = $result;
34
			
35
			return $this->results;
36
		} else {
37
			return false;
38
		}
39
	}
40
}