CandidatesModel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getCandidatesByConstituencyId() 0 24 3
1
<?php
2
namespace Kineo\Model;
3
4
use Kineo\Component\Database;
5
6
class CandidatesModel extends BaseModel 
7
{
8
	protected $db;
9
	
10
	public $candidates = array();
11
	
12
	public function __construct(Database $db)
13
	{
14
		$this->db = $db;
15
	}
16
	
17
	public function getCandidatesByConstituencyId($constituencyId) 
18
	{
19
		$stmt = $this->db->prepare(
20
			"SELECT a.id, a.name, a.party FROM `tblCandidates` AS a 
21
			LEFT JOIN `tblConstituencies` AS b 
22
			ON a.constituency_id = b.id 
23
			WHERE b.id = :id
24
			ORDER BY a.name ASC"
25
		);
26
		
27
		$stmt->bindValue(':id', $constituencyId, \PDO::PARAM_INT);
28
		
29
		$stmt->execute();
30
		
31
		$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
32
		
33
		if(is_array($result) && !empty($result)) {
34
			$this->candidates = $result;
35
			
36
			return $this->candidates;
37
		} else {
38
			return false;
39
		}
40
	}
41
}